Index: lib/Lex/Lexer.cpp =================================================================== --- lib/Lex/Lexer.cpp +++ lib/Lex/Lexer.cpp @@ -2668,14 +2668,16 @@ /// \brief Find the end of a version control conflict marker. static const char *FindConflictEnd(const char *CurPtr, const char *BufferEnd, ConflictMarkerKind CMK) { - const char *Terminator = CMK == CMK_Perforce ? "<<<<\n" : ">>>>>>>"; - size_t TermLen = CMK == CMK_Perforce ? 5 : 7; + const char *Terminator = CMK == CMK_Perforce ? "<<<<" : ">>>>>>>"; + size_t TermLen = CMK == CMK_Perforce ? 4 : 7; auto RestOfBuffer = StringRef(CurPtr, BufferEnd - CurPtr).substr(TermLen); size_t Pos = RestOfBuffer.find(Terminator); while (Pos != StringRef::npos) { // Must occur at start of line. if (Pos == 0 || - (RestOfBuffer[Pos - 1] != '\r' && RestOfBuffer[Pos - 1] != '\n')) { + (RestOfBuffer[Pos - 1] != '\r' && RestOfBuffer[Pos - 1] != '\n') || + (CMK == CMK_Perforce && Pos + 4 < RestOfBuffer.size() && + RestOfBuffer[Pos + 4] != '\r' && RestOfBuffer[Pos + 4] != '\n')) { RestOfBuffer = RestOfBuffer.substr(Pos+TermLen); Pos = RestOfBuffer.find(Terminator); continue; Index: test/Lexer/conflict-marker.c =================================================================== --- test/Lexer/conflict-marker.c +++ test/Lexer/conflict-marker.c @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 %s -verify -fsyntax-only +// RUN: unix2dos %s | %clang_cc1 -verify -fsyntax-only +// RUN: dos2unix %s | %clang_cc1 -verify -fsyntax-only // Test that we recover gracefully from conflict markers left in input files. // PR5238 Index: test/lit.cfg.py =================================================================== --- test/lit.cfg.py +++ test/lit.cfg.py @@ -49,6 +49,12 @@ config.substitutions.append(('%PATH%', config.environment['PATH'])) +if platform.system() in ['Windows']: + config.substitutions.append(('dos2unix', 'sed -b "s/\r$//"')) + config.substitutions.append(('unix2dos', 'sed -b "s/\r*$/\r/"')) +else: + config.substitutions.append(('dos2unix', "sed $'s/\r$//'")) + config.substitutions.append(('unix2dos', "sed $'s/\r*$/\r/'")) # For each occurrence of a clang tool name, replace it with the full path to # the build directory holding that tool. We explicitly specify the directories