llvm.org GIT mirror llvm / e5f740c
Really fix CHECK-LABEL and CHECK-DAG interaction. This actually just restores the initial implementation that was in r186162 but got lost in some subsequent refactoring. More explicit variable names and comments are present now to hopefully prevent repeat regression, as well as another test. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192477 91177308-0d34-0410-b5e6-96231b3b80d8 Stephen Lin 6 years ago
2 changed file(s) with 28 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
0 ; RUN: FileCheck -input-file %s %s
1
2 bar
3 foo
4 foo
5 zed
6
7 CHECK-LABEL: {{^}}bar
8 CHECK: {{^}}[[FOO:foo]]
9 CHECK-DAG: {{^}}[[FOO]]
10 CHECK-LABEL: {{^}}zed
608608 : Pat(P), Loc(L), CheckTy(Ty) {}
609609
610610 /// Check - Match check string and its "not strings" and/or "dag strings".
611 size_t Check(const SourceMgr &SM, StringRef Buffer,
611 size_t Check(const SourceMgr &SM, StringRef Buffer, bool IsLabelScanMode,
612612 size_t &MatchLen, StringMap &VariableTable) const;
613613
614614 /// CheckNext - Verify there is a single line in the given buffer.
873873 }
874874
875875 size_t CheckString::Check(const SourceMgr &SM, StringRef Buffer,
876 size_t &MatchLen,
876 bool IsLabelScanMode, size_t &MatchLen,
877877 StringMap &VariableTable) const {
878878 size_t LastPos = 0;
879879 std::vector NotStrings;
880880
881 // Match "dag strings" (with mixed "not strings" if any).
882 LastPos = CheckDag(SM, Buffer, NotStrings, VariableTable);
883 if (LastPos == StringRef::npos)
884 return StringRef::npos;
881 // IsLabelScanMode is true when we are scanning forward to find CHECK-LABEL
882 // bounds; we have not processed variable definitions within the bounded block
883 // yet so cannot handle any final CHECK-DAG yet; this is handled when going
884 // over the block again (including the last CHECK-LABEL) in normal mode.
885 if (!IsLabelScanMode) {
886 // Match "dag strings" (with mixed "not strings" if any).
887 LastPos = CheckDag(SM, Buffer, NotStrings, VariableTable);
888 if (LastPos == StringRef::npos)
889 return StringRef::npos;
890 }
885891
886892 // Match itself from the last position after matching CHECK-DAG.
887893 StringRef MatchBuffer = Buffer.substr(LastPos);
892898 }
893899 MatchPos += LastPos;
894900
895 if (CheckTy != Check::CheckLabel) {
901 // Similar to the above, in "label-scan mode" we can't yet handle CHECK-NEXT
902 // or CHECK-NOT
903 if (!IsLabelScanMode) {
896904 StringRef SkippedRegion = Buffer.substr(LastPos, MatchPos);
897905
898906 // If this check is a "CHECK-NEXT", verify that the previous match was on
11161124
11171125 // Scan to next CHECK-LABEL match, ignoring CHECK-NOT and CHECK-DAG
11181126 size_t MatchLabelLen = 0;
1119 size_t MatchLabelPos = CheckLabelStr.Check(SM, Buffer,
1127 size_t MatchLabelPos = CheckLabelStr.Check(SM, Buffer, true,
11201128 MatchLabelLen, VariableTable);
11211129 if (MatchLabelPos == StringRef::npos) {
11221130 hasError = true;
11341142 // Check each string within the scanned region, including a second check
11351143 // of any final CHECK-LABEL (to verify CHECK-NOT and CHECK-DAG)
11361144 size_t MatchLen = 0;
1137 size_t MatchPos = CheckStr.Check(SM, CheckRegion, MatchLen,
1145 size_t MatchPos = CheckStr.Check(SM, CheckRegion, false, MatchLen,
11381146 VariableTable);
11391147
11401148 if (MatchPos == StringRef::npos) {