llvm.org GIT mirror llvm / d9a84ef
[FileCheck] Fix a bug that cause FileCheck to misidentify check-prefix FileCheck should check to make sure the prefix was found, and not a word containing it (e.g -check-prefix=BASEREL shouldn't match NOBASEREL). Patch by Ron Ofir. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188221 91177308-0d34-0410-b5e6-96231b3b80d8 Rui Ueyama 6 years ago
3 changed file(s) with 43 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
0 // RUN: FileCheck -check-prefix=ANOTHER-PREFIX -input-file %s %s
1 // RUN: not FileCheck -check-prefix=PREFIX -input-file %s %s 2>&1 | FileCheck -check-prefix=CHECK-NONEXISTANT-PREFIX %s
2
3 foobar
4 ; ANOTHER-PREFIX: foobar
5
6 ; We use regex to match the colon so that FileCheck won't think it is a check
7 ; prefix.
8 ; CHECK-NONEXISTANT-PREFIX: error: no check strings found with prefix 'PREFIX{{:}}'
0 // RUN: not FileCheck -check-prefix=A! -input-file %s %s 2>&1 | FileCheck -check-prefix=BAD_PREFIX %s
1 // RUN: FileCheck -check-prefix=A1a-B_c -input-file %s %s
2
3 foobar
4 ; A1a-B_c: foobar
5
6 ; BAD_PREFIX: Supplied check-prefix is invalid! Prefixes must start with a letter and contain only alphanumeric characters, hyphens and underscores
703703
704704 LineNumber += Buffer.substr(0, PrefixLoc).count('\n');
705705
706 Buffer = Buffer.substr(PrefixLoc);
707
708 const char *CheckPrefixStart = Buffer.data();
706 // Keep the charcter before our prefix so we can validate that we have
707 // found our prefix, and account for cases when PrefixLoc is 0.
708 Buffer = Buffer.substr(std::min(PrefixLoc-1, PrefixLoc));
709
710 const char *CheckPrefixStart = Buffer.data() + (PrefixLoc == 0 ? 0 : 1);
709711
710712 // When we find a check prefix, keep track of whether we find CHECK: or
711713 // CHECK-NEXT:
712714 bool IsCheckNext = false, IsCheckNot = false, IsCheckDag = false,
713715 IsCheckLabel = false;
716
717 // Make sure we have actually found our prefix, and not a word containing
718 // our prefix.
719 if (PrefixLoc != 0 && (isalnum(Buffer[0]) ||
720 Buffer[0] == '-' ||
721 Buffer[0] == '_')) {
722 Buffer = Buffer.substr(CheckPrefix.size());
723 continue;
724 }
714725
715726 // Verify that the : is present after the prefix.
716727 if (Buffer[CheckPrefix.size()] == ':') {
10251036 return LastPos;
10261037 }
10271038
1039 bool ValidateCheckPrefix() {
1040 // The check prefix must contain only alphanumeric, hyphens and underscores.
1041 Regex prefixValidator("^[a-zA-Z0-9_-]*$");
1042 return prefixValidator.match(CheckPrefix);
1043 }
1044
10281045 int main(int argc, char **argv) {
10291046 sys::PrintStackTraceOnErrorSignal();
10301047 PrettyStackTraceProgram X(argc, argv);
10311048 cl::ParseCommandLineOptions(argc, argv);
1049
1050 if (!ValidateCheckPrefix()) {
1051 errs() << "Supplied check-prefix is invalid! Prefixes must start with a "
1052 "letter and contain only alphanumeric characters, hyphens and "
1053 "underscores\n";
1054 return 2;
1055 }
10321056
10331057 SourceMgr SM;
10341058