From b9454635c0f598c66402692e3e8370f263592b83 Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Tue, 20 Jun 2017 01:38:56 +0000 Subject: [ProfileData] PR33517: Check for failure of symtab creation With PR33517, it became apparent that symbol table creation can fail when presented with malformed inputs. This patch makes that sort of error detectable, so llvm-cov etc. can fail more gracefully. Specifically, we now check that function names within the symbol table aren't empty. Testing: check-{llvm,clang,profile}, some unit test updates. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305765 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/ProfileData/InstrProfTest.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'unittests') diff --git a/unittests/ProfileData/InstrProfTest.cpp b/unittests/ProfileData/InstrProfTest.cpp index b15029a08137..13436cc0d5b2 100644 --- a/unittests/ProfileData/InstrProfTest.cpp +++ b/unittests/ProfileData/InstrProfTest.cpp @@ -859,7 +859,7 @@ TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_test) { FuncNames.push_back("bar2"); FuncNames.push_back("bar3"); InstrProfSymtab Symtab; - Symtab.create(FuncNames); + NoError(Symtab.create(FuncNames)); StringRef R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("func1")); ASSERT_EQ(StringRef("func1"), R); R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("func2")); @@ -880,9 +880,9 @@ TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_test) { ASSERT_EQ(StringRef(), R); // Now incrementally update the symtab - Symtab.addFuncName("blah_1"); - Symtab.addFuncName("blah_2"); - Symtab.addFuncName("blah_3"); + NoError(Symtab.addFuncName("blah_1")); + NoError(Symtab.addFuncName("blah_2")); + NoError(Symtab.addFuncName("blah_3")); // Finalize it Symtab.finalizeSymtab(); @@ -907,6 +907,12 @@ TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_test) { ASSERT_EQ(StringRef("bar3"), R); } +// Test that we get an error when creating a bogus symtab. +TEST_P(MaybeSparseInstrProfTest, instr_prof_bogus_symtab_empty_func_name) { + InstrProfSymtab Symtab; + ErrorEquals(instrprof_error::malformed, Symtab.addFuncName("")); +} + // Testing symtab creator interface used by value profile transformer. TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_module_test) { LLVMContext Ctx; @@ -927,7 +933,7 @@ TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_module_test) { Function::Create(FTy, Function::WeakODRLinkage, "Wbar", M.get()); InstrProfSymtab ProfSymtab; - ProfSymtab.create(*M); + NoError(ProfSymtab.create(*M)); StringRef Funcs[] = {"Gfoo", "Gblah", "Gbar", "Ifoo", "Iblah", "Ibar", "Pfoo", "Pblah", "Pbar", "Wfoo", "Wblah", "Wbar"}; -- cgit v1.2.3