From 71981ef040dd94438449aeca726cab5839d8ec3c Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Tue, 16 Jul 2013 17:56:07 +0000 Subject: [PATCH 1/1] Make SpecialCaseList match full strings, as documented, using anchors. Differential Revision: http://llvm-reviews.chandlerc.com/D1149 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186431 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/SpecialCaseList.cpp | 2 +- unittests/Transforms/Utils/SpecialCaseList.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/Utils/SpecialCaseList.cpp b/lib/Transforms/Utils/SpecialCaseList.cpp index a747230def2..ef8a7ac75b6 100644 --- a/lib/Transforms/Utils/SpecialCaseList.cpp +++ b/lib/Transforms/Utils/SpecialCaseList.cpp @@ -99,7 +99,7 @@ void SpecialCaseList::init(const MemoryBuffer *MB) { // Add this regexp into the proper group by its prefix. if (!Regexps[Prefix][Category].empty()) Regexps[Prefix][Category] += "|"; - Regexps[Prefix][Category] += Regexp; + Regexps[Prefix][Category] += "^" + Regexp + "$"; } // Iterate through each of the prefixes, and create Regexs for them. diff --git a/unittests/Transforms/Utils/SpecialCaseList.cpp b/unittests/Transforms/Utils/SpecialCaseList.cpp index d87dab00db9..9deee3c1e9d 100644 --- a/unittests/Transforms/Utils/SpecialCaseList.cpp +++ b/unittests/Transforms/Utils/SpecialCaseList.cpp @@ -139,4 +139,20 @@ TEST_F(SpecialCaseListTest, GlobalIsIn) { EXPECT_TRUE(SCL->isIn(*Bar, "init")); } +TEST_F(SpecialCaseListTest, Substring) { + Module M("othello", Ctx); + Function *F = makeFunction("tomfoolery", M); + GlobalVariable *GV = makeGlobal("bartender", "t", M); + + OwningPtr SCL(makeSpecialCaseList("src:hello\n" + "fun:foo\n" + "global:bar\n")); + EXPECT_FALSE(SCL->isIn(M)); + EXPECT_FALSE(SCL->isIn(*F)); + EXPECT_FALSE(SCL->isIn(*GV)); + + SCL.reset(makeSpecialCaseList("fun:*foo*\n")); + EXPECT_TRUE(SCL->isIn(*F)); +} + } -- 2.34.1