Skip to content

Commit

Permalink
IR: Allow 32-bits for lines in debug location
Browse files Browse the repository at this point in the history
Remove unnecessary restriction of 24-bits for line numbers in
`MDLocation`.

The rest of the debug info schema (with the exception of local
variables) uses 32-bits for line numbers.  As I introduce the
specialized nodes, it makes sense to canonicalize on one size or the
other.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228455 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
dexonsmith committed Feb 6, 2015
1 parent 4752dab commit 8713d99
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2946,7 +2946,7 @@ struct MDUnsignedField : public MDFieldImpl<uint64_t> {
: ImplTy(Default), Max(Max) {}
};
struct LineField : public MDUnsignedField {
LineField() : MDUnsignedField(0, UINT32_MAX >> 8) {}
LineField() : MDUnsignedField(0, UINT32_MAX) {}
};
struct ColumnField : public MDUnsignedField {
ColumnField() : MDUnsignedField(0, UINT16_MAX) {}
Expand Down
10 changes: 1 addition & 9 deletions lib/IR/DebugInfoMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,12 @@ MDLocation::MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
"Expected a scope and optional inlined-at");

// Set line and column.
assert(Line < (1u << 24) && "Expected 24-bit line");
assert(Column < (1u << 16) && "Expected 16-bit column");

SubclassData32 = Line;
SubclassData16 = Column;
}

static void adjustLine(unsigned &Line) {
// Set to unknown on overflow. Still use 24 bits for now.
if (Line >= (1u << 24))
Line = 0;
}

static void adjustColumn(unsigned &Column) {
// Set to unknown on overflow. We only have 16 bits to play with here.
if (Column >= (1u << 16))
Expand All @@ -47,8 +40,7 @@ MDLocation *MDLocation::getImpl(LLVMContext &Context, unsigned Line,
unsigned Column, Metadata *Scope,
Metadata *InlinedAt, StorageType Storage,
bool ShouldCreate) {
// Fixup line/column.
adjustLine(Line);
// Fixup column.
adjustColumn(Column);

if (Storage == Uniqued) {
Expand Down
6 changes: 3 additions & 3 deletions test/Assembler/invalid-mdlocation-overflow-line.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
!0 = !{}

; CHECK-NOT: error
!1 = !MDLocation(line: 16777215, scope: !0)
!1 = !MDLocation(line: 4294967295, scope: !0)

; CHECK: <stdin>:[[@LINE+1]]:24: error: value for 'line' too large, limit is 16777215
!2 = !MDLocation(line: 16777216, scope: !0)
; CHECK: <stdin>:[[@LINE+1]]:24: error: value for 'line' too large, limit is 4294967295
!2 = !MDLocation(line: 4294967296, scope: !0)
4 changes: 2 additions & 2 deletions test/Assembler/mdlocation.ll
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
!5 = !MDLocation(scope: !0)
!6 = !MDLocation(scope: !0, column: 0, line: 0)

; CHECK-NEXT: !4 = !MDLocation(line: 16777215, column: 65535, scope: !0)
!7 = !MDLocation(line: 16777215, column: 65535, scope: !0)
; CHECK-NEXT: !4 = !MDLocation(line: 4294967295, column: 65535, scope: !0)
!7 = !MDLocation(line: 4294967295, column: 65535, scope: !0)
13 changes: 6 additions & 7 deletions unittests/IR/MetadataTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,21 +538,20 @@ TEST_F(MDLocationTest, Overflow) {
EXPECT_EQ(2u, L->getLine());
EXPECT_EQ(7u, L->getColumn());
}
unsigned U24 = 1u << 24;
unsigned U16 = 1u << 16;
{
MDLocation *L = MDLocation::get(Context, U24 - 1, U16 - 1, N);
EXPECT_EQ(U24 - 1, L->getLine());
MDLocation *L = MDLocation::get(Context, UINT32_MAX, U16 - 1, N);
EXPECT_EQ(UINT32_MAX, L->getLine());
EXPECT_EQ(U16 - 1, L->getColumn());
}
{
MDLocation *L = MDLocation::get(Context, U24, U16, N);
EXPECT_EQ(0u, L->getLine());
MDLocation *L = MDLocation::get(Context, UINT32_MAX, U16, N);
EXPECT_EQ(UINT32_MAX, L->getLine());
EXPECT_EQ(0u, L->getColumn());
}
{
MDLocation *L = MDLocation::get(Context, U24 + 1, U16 + 1, N);
EXPECT_EQ(0u, L->getLine());
MDLocation *L = MDLocation::get(Context, UINT32_MAX, U16 + 1, N);
EXPECT_EQ(UINT32_MAX, L->getLine());
EXPECT_EQ(0u, L->getColumn());
}
}
Expand Down

0 comments on commit 8713d99

Please sign in to comment.