Skip to content

Commit

Permalink
DI: Set DILexicalBlock columns >= 65536 to 0/unknown
Browse files Browse the repository at this point in the history
This fixes PR24621 and matches what we do for `DILocation`.  Although
the limit seems somewhat artificial, there are places in the backend
that also assume 16-bit columns, so we may as well just be consistent
about the limits.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@246349 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
dexonsmith committed Aug 28, 2015
1 parent cf5151a commit 091adc7
Showing 3 changed files with 33 additions and 2 deletions.
6 changes: 4 additions & 2 deletions include/llvm/IR/DebugInfoMetadata.h
Original file line number Diff line number Diff line change
@@ -1430,12 +1430,14 @@ class DILexicalBlock : public DILexicalBlockBase {
friend class MDNode;

unsigned Line;
unsigned Column;
uint16_t Column;

DILexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
unsigned Column, ArrayRef<Metadata *> Ops)
: DILexicalBlockBase(C, DILexicalBlockKind, Storage, Ops), Line(Line),
Column(Column) {}
Column(Column) {
assert(Column < (1u << 16) && "Expected 16-bit column");
}
~DILexicalBlock() = default;

static DILexicalBlock *getImpl(LLVMContext &Context, DILocalScope *Scope,
3 changes: 3 additions & 0 deletions lib/IR/DebugInfoMetadata.cpp
Original file line number Diff line number Diff line change
@@ -386,6 +386,9 @@ DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
Metadata *File, unsigned Line,
unsigned Column, StorageType Storage,
bool ShouldCreate) {
// Fixup column.
adjustColumn(Column);

assert(Scope && "Expected scope");
DEFINE_GETIMPL_LOOKUP(DILexicalBlock, (Scope, File, Line, Column));
Metadata *Ops[] = {File, Scope};
26 changes: 26 additions & 0 deletions unittests/IR/MetadataTest.cpp
Original file line number Diff line number Diff line change
@@ -1591,6 +1591,32 @@ TEST_F(DILexicalBlockTest, get) {
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
}

TEST_F(DILexicalBlockTest, Overflow) {
DISubprogram *SP = getSubprogram();
DIFile *F = getFile();
{
auto *LB = DILexicalBlock::get(Context, SP, F, 2, 7);
EXPECT_EQ(2u, LB->getLine());
EXPECT_EQ(7u, LB->getColumn());
}
unsigned U16 = 1u << 16;
{
auto *LB = DILexicalBlock::get(Context, SP, F, UINT32_MAX, U16 - 1);
EXPECT_EQ(UINT32_MAX, LB->getLine());
EXPECT_EQ(U16 - 1, LB->getColumn());
}
{
auto *LB = DILexicalBlock::get(Context, SP, F, UINT32_MAX, U16);
EXPECT_EQ(UINT32_MAX, LB->getLine());
EXPECT_EQ(0u, LB->getColumn());
}
{
auto *LB = DILexicalBlock::get(Context, SP, F, UINT32_MAX, U16 + 1);
EXPECT_EQ(UINT32_MAX, LB->getLine());
EXPECT_EQ(0u, LB->getColumn());
}
}

typedef MetadataTest DILexicalBlockFileTest;

TEST_F(DILexicalBlockFileTest, get) {

0 comments on commit 091adc7

Please sign in to comment.