Skip to content

[DebugInfo] Fix faulty DIExpression::appendToStack assert #85255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions llvm/lib/IR/DebugInfoMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1880,11 +1880,12 @@ DIExpression *DIExpression::append(const DIExpression *Expr,
DIExpression *DIExpression::appendToStack(const DIExpression *Expr,
ArrayRef<uint64_t> Ops) {
assert(Expr && !Ops.empty() && "Can't append ops to this expression");
assert(none_of(Ops,
[](uint64_t Op) {
return Op == dwarf::DW_OP_stack_value ||
Op == dwarf::DW_OP_LLVM_fragment;
}) &&
assert(std::none_of(expr_op_iterator(Ops.begin()),
expr_op_iterator(Ops.end()),
[](auto Op) {
return Op.getOp() == dwarf::DW_OP_stack_value ||
Op.getOp() == dwarf::DW_OP_LLVM_fragment;
}) &&
"Can't append this op");

// Append a DW_OP_deref after Expr's current op list if it's non-empty and
Expand Down
21 changes: 21 additions & 0 deletions llvm/unittests/IR/MetadataTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3560,6 +3560,27 @@ TEST_F(DIExpressionTest, foldConstant) {
#undef EXPECT_FOLD_CONST
}

TEST_F(DIExpressionTest, appendToStackAssert) {
DIExpression *Expr = DIExpression::get(Context, {});

// Verify that the DW_OP_LLVM_convert operands, which have the same values as
// DW_OP_stack_value and DW_OP_LLVM_fragment, do not get interpreted as such
// operations. This previously triggered an assert.
uint64_t FromSize = dwarf::DW_OP_stack_value;
uint64_t ToSize = dwarf::DW_OP_LLVM_fragment;
uint64_t Ops[] = {
dwarf::DW_OP_LLVM_convert, FromSize, dwarf::DW_ATE_signed,
dwarf::DW_OP_LLVM_convert, ToSize, dwarf::DW_ATE_signed,
};
Expr = DIExpression::appendToStack(Expr, Ops);

uint64_t Expected[] = {
dwarf::DW_OP_LLVM_convert, FromSize, dwarf::DW_ATE_signed,
dwarf::DW_OP_LLVM_convert, ToSize, dwarf::DW_ATE_signed,
dwarf::DW_OP_stack_value};
EXPECT_EQ(Expr->getElements(), ArrayRef<uint64_t>(Expected));
}

typedef MetadataTest DIObjCPropertyTest;

TEST_F(DIObjCPropertyTest, get) {
Expand Down