summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-08-28 22:58:50 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-08-28 22:58:50 +0000
commitb09eb9f1c2b2e36b49b32e149a82a49380a4f4b0 (patch)
treee31cb5ae9ad2438b05b9c3cd069b4176c099604b /llvm
parenta37b065e8fa57ae40d14dfdb5afed4628129b1ea (diff)
downloadbcm5719-llvm-b09eb9f1c2b2e36b49b32e149a82a49380a4f4b0.tar.gz
bcm5719-llvm-b09eb9f1c2b2e36b49b32e149a82a49380a4f4b0.zip
DI: Set DILexicalBlock columns >= 65536 to 0/unknown
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. llvm-svn: 246349
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/IR/DebugInfoMetadata.h6
-rw-r--r--llvm/lib/IR/DebugInfoMetadata.cpp3
-rw-r--r--llvm/unittests/IR/MetadataTest.cpp26
3 files changed, 33 insertions, 2 deletions
diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h
index eeacbdbf343..6fba3b59396 100644
--- a/llvm/include/llvm/IR/DebugInfoMetadata.h
+++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -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,
diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp
index 89111f73ae2..3c293c25c91 100644
--- a/llvm/lib/IR/DebugInfoMetadata.cpp
+++ b/llvm/lib/IR/DebugInfoMetadata.cpp
@@ -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};
diff --git a/llvm/unittests/IR/MetadataTest.cpp b/llvm/unittests/IR/MetadataTest.cpp
index 6741c79afc9..661f965660e 100644
--- a/llvm/unittests/IR/MetadataTest.cpp
+++ b/llvm/unittests/IR/MetadataTest.cpp
@@ -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) {
OpenPOWER on IntegriCloud