IR: Canonicalize GenericDwarfNode empty headers to null

llvm-svn: 226532
This commit is contained in:
Duncan P. N. Exon Smith 2015-01-20 00:58:46 +00:00
parent 0f529998a5
commit 2da09e4408
2 changed files with 12 additions and 0 deletions

View File

@ -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);

View File

@ -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) {