summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-01-20 00:58:46 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-01-20 00:58:46 +0000
commit2da09e44082b3caea7ab6347af522ece9a29edd9 (patch)
tree9f697967349b64fbce28dcbd028861c62e4cdbb3 /llvm
parent0f529998a5355fde5662719c56e74492802cb816 (diff)
downloadbcm5719-llvm-2da09e44082b3caea7ab6347af522ece9a29edd9.tar.gz
bcm5719-llvm-2da09e44082b3caea7ab6347af522ece9a29edd9.zip
IR: Canonicalize GenericDwarfNode empty headers to null
llvm-svn: 226532
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/IR/Metadata.cpp4
-rw-r--r--llvm/unittests/IR/MetadataTest.cpp8
2 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index 97976308fcd..fc1f3e7a3cf 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -753,6 +753,10 @@ GenericDwarfNode *GenericDwarfNode::getImpl(LLVMContext &Context, unsigned Tag,
ArrayRef<Metadata *> DwarfOps,
StorageType Storage,
bool ShouldCreate) {
+ // Canonicalize empty string to a nullptr.
+ if (Header && Header->getString().empty())
+ Header = nullptr;
+
unsigned Hash = 0;
if (Storage == Uniqued) {
GenericDwarfNodeInfo::KeyTy Key(Tag, Header, DwarfOps);
diff --git a/llvm/unittests/IR/MetadataTest.cpp b/llvm/unittests/IR/MetadataTest.cpp
index f2140d62172..e2ed3d7946b 100644
--- a/llvm/unittests/IR/MetadataTest.cpp
+++ b/llvm/unittests/IR/MetadataTest.cpp
@@ -596,6 +596,14 @@ TEST_F(GenericDwarfNodeTest, get) {
EXPECT_EQ(N, GenericDwarfNode::get(Context, 15, Header, Ops1));
}
+TEST_F(GenericDwarfNodeTest, getEmptyHeader) {
+ // Canonicalize !"" to null.
+ auto *Header = MDString::get(Context, "");
+ EXPECT_NE(nullptr, Header);
+ auto *N = GenericDwarfNode::get(Context, 15, Header, None);
+ EXPECT_EQ(nullptr, N->getHeader());
+}
+
typedef MetadataTest MetadataAsValueTest;
TEST_F(MetadataAsValueTest, MDNode) {
OpenPOWER on IntegriCloud