Skip to content

Commit 9412f74

Browse files
authored
[Verifier] Fix some debug expression input type checks (llvm#666)
2 parents 5a830f6 + f839da3 commit 9412f74

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3036,16 +3036,14 @@ template <class Derived> class DIExprConstVisitor {
30363036
}
30373037

30383038
std::optional<Type *> getType(DIOp::BitOffset Op, ArrayRef<StackEntry> Ins) {
3039-
if (!Ins[0].ResultType->isIntegerTy())
3040-
return getTypeError(
3041-
"DIOpBitOffset requires first input be integer typed");
3039+
if (!Ins[1].ResultType->isIntegerTy())
3040+
return getTypeError("DIOpBitOffset requires an integer typed offset");
30423041
return Op.getResultType();
30433042
}
30443043

30453044
std::optional<Type *> getType(DIOp::ByteOffset Op, ArrayRef<StackEntry> Ins) {
3046-
if (!Ins[0].ResultType->isIntegerTy())
3047-
return getTypeError(
3048-
"DIOpByteOffset requires first input be integer typed");
3045+
if (!Ins[1].ResultType->isIntegerTy())
3046+
return getTypeError("DIOpByteOffset requires an integer typed offset");
30493047
return Op.getResultType();
30503048
}
30513049

@@ -3066,13 +3064,12 @@ template <class Derived> class DIExprConstVisitor {
30663064
}
30673065

30683066
std::optional<Type *> getType(DIOp::Select Op, ArrayRef<StackEntry> Ins) {
3069-
if (Ins[0].ResultType != Ins[1].ResultType)
3070-
return getTypeError(
3071-
"DIOpSelect requires first two inputs have same type");
3072-
if (!Ins[0].ResultType->isVectorTy())
3067+
if (Ins[1].ResultType != Ins[2].ResultType)
30733068
return getTypeError(
3074-
"DIOpSelect requires first two inputs to be vector typed");
3075-
return Ins[0].ResultType;
3069+
"DIOpSelect requires vector inputs to have same type");
3070+
if (!Ins[1].ResultType->isVectorTy())
3071+
return getTypeError("non-mask DIOpSelect inputs must have vector type");
3072+
return Ins[1].ResultType;
30763073
}
30773074

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

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

Lines changed: 15 additions & 2 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
#dbg_declare(i8 poison, !24, !DIExpression(DIOpArg(0, i32)), !22)
2828

29+
; CHECK: #dbg_declare(ptr %i, ![[#]], !DIExpression(DIOpArg(0, ptr), DIOpDeref(%struct.type), DIOpConstant(i32 64), DIOpBitOffset(ptr)), ![[#]])
30+
#dbg_declare(ptr %i, !26, !DIExpression(DIOpArg(0, ptr), DIOpDeref(%struct.type), DIOpConstant(i32 64), DIOpBitOffset(ptr)), !22)
31+
32+
; CHECK: #dbg_declare(ptr %i, ![[#]], !DIExpression(DIOpArg(0, ptr), DIOpDeref(%struct.type), DIOpConstant(i32 8), DIOpByteOffset(ptr)), ![[#]])
33+
#dbg_declare(ptr %i, !27, !DIExpression(DIOpArg(0, ptr), DIOpDeref(%struct.type), DIOpConstant(i32 8), DIOpByteOffset(ptr)), !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+
#dbg_declare(i32 3, !28, !DIExpression(DIOpArg(0, i32), DIOpConstant(<2 x i32> <i32 1, i32 2>), DIOpConstant(<2 x i32> <i32 3, i32 4>), DIOpSelect()), !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
@@ -81,10 +94,10 @@ entry:
8194
; CHECK: DIOpReinterpret must not alter bitsize of child
8295
#dbg_declare(ptr %x, !18, !DIExpression(DIOpArg(0, ptr), DIOpReinterpret(i32)), !20)
8396

84-
; CHECK: DIOpBitOffset requires first input be integer typed
97+
; CHECK: DIOpBitOffset requires an integer typed offset
8598
#dbg_declare(ptr %x, !18, !DIExpression(DIOpConstant(float 0.0), DIOpArg(0, ptr), DIOpBitOffset(ptr)), !20)
8699

87-
; CHECK: DIOpByteOffset requires first input be integer typed
100+
; CHECK: DIOpByteOffset requires an integer typed offset
88101
#dbg_declare(ptr %x, !18, !DIExpression(DIOpConstant(ptr undef), DIOpArg(0, ptr), DIOpByteOffset(ptr)), !20)
89102

90103
; CHECK: DIOpComposite bitsize does not match sum of child bitsizes

0 commit comments

Comments
 (0)