Skip to content

Commit 6eadb5a

Browse files
committed
Fix LIT test.
1 parent 19806c1 commit 6eadb5a

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

clang/lib/Frontend/PrintPreprocessedOutput.cpp

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,48 @@ void PrintPPOutputPPCallbacks::WriteFooterContent(StringRef CodeFooter) {
265265
*OS << '\n';
266266
}
267267

268+
static bool is_separator(char value) {
269+
if (value == '\\')
270+
return true;
271+
return false;
272+
}
273+
274+
static StringRef remove_leading_dotbackslah(StringRef Path) {
275+
// Remove leading ".\" (or ".\\" or ".\.\" etc.)
276+
while (Path.size() > 2 && Path[0] == '.' && is_separator(Path[1])) {
277+
Path = Path.substr(2);
278+
while (Path.size() > 0 && is_separator(Path[0]))
279+
Path = Path.substr(1);
280+
}
281+
return Path;
282+
}
283+
268284
void PrintPPOutputPPCallbacks::WriteLineInfo(unsigned LineNo,
269285
const char *Extra,
270286
unsigned ExtraLen) {
271287
startNewLineIfNeeded();
272288

273289
// Emit #line directives or GNU line markers depending on what mode we're in.
274-
if (CurFilename != PP.getPreprocessorOpts().IncludeFooter &&
275-
CurFilename != PP.getPreprocessorOpts().IncludeHeader) {
290+
printf("CurFileName: %s\n", CurFilename.c_str());
291+
StringRef CurFilenameWithNoLeaningDotSlash =
292+
remove_leading_dotbackslah(CurFilename.str());
293+
printf("CurFilenameWithNoLeaningDotSlash: %s\n",
294+
CurFilenameWithNoLeaningDotSlash.data());
295+
printf("Footer: %s\n", PP.getPreprocessorOpts().IncludeFooter.data());
296+
printf("Header: %s\n", PP.getPreprocessorOpts().IncludeHeader.data());
297+
if (strcmp(CurFilenameWithNoLeaningDotSlash.data(),
298+
PP.getPreprocessorOpts().IncludeFooter.data()) == 0)
299+
printf("%s and %s are equal\n", CurFilename.c_str(), PP.getPreprocessorOpts().IncludeFooter.data());
300+
if (strcmp(CurFilenameWithNoLeaningDotSlash.data(),
301+
PP.getPreprocessorOpts().IncludeHeader.data()) == 0)
302+
printf("%s and %s are equal\n", CurFilename.c_str(),
303+
PP.getPreprocessorOpts().IncludeHeader.data());
304+
if ((strcmp(CurFilenameWithNoLeaningDotSlash.data(),
305+
PP.getPreprocessorOpts().IncludeFooter.data()) == 0) ||
306+
(strcmp(CurFilenameWithNoLeaningDotSlash.data(),
307+
PP.getPreprocessorOpts().IncludeHeader.data()) == 0)) {
308+
CurFilename = StringRef();
309+
}
276310
if (UseLineDirectives) {
277311
*OS << "#line" << ' ' << LineNo << ' ' << '"';
278312
OS->write_escaped(CurFilename);
@@ -290,7 +324,7 @@ void PrintPPOutputPPCallbacks::WriteLineInfo(unsigned LineNo,
290324
else if (FileType == SrcMgr::C_ExternCSystem)
291325
OS->write(" 3 4", 4);
292326
}
293-
}
327+
294328
*OS << '\n';
295329
}
296330

0 commit comments

Comments
 (0)