john.brawn updated this revision to Diff 502683.
john.brawn edited the summary of this revision.
john.brawn added a comment.
Herald added subscribers: kadircet, arphaman, ilya-biryukov.
Herald added a project: clang-tools-extra.
Fixed a couple of things causing failures in clangd tests (path being prepended
in front of <command line>, and a bit of code assuming that command-line macros
were builtin).
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D144651/new/
https://reviews.llvm.org/D144651
Files:
clang-tools-extra/clangd/index/SymbolCollector.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/PCH/macro-cmdline.c
clang/test/PCH/ms-pch-macro.c
Index: clang/test/PCH/ms-pch-macro.c
===================================================================
--- clang/test/PCH/ms-pch-macro.c
+++ clang/test/PCH/ms-pch-macro.c
@@ -36,4 +36,4 @@
// CHECK-FOO: definition of macro 'FOO' differs between the precompiled header ('1') and the command line ('blah')
// CHECK-NOFOO: macro 'FOO' was defined in the precompiled header but undef'd on the command line
-// expected-warning@1 {{definition of macro 'BAR' does not match definition in precompiled header}}
+// expected-warning@2 {{definition of macro 'BAR' does not match definition in precompiled header}}
Index: clang/test/PCH/macro-cmdline.c
===================================================================
--- /dev/null
+++ clang/test/PCH/macro-cmdline.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -emit-pch -o %t1.pch -DMACRO1=1
+// RUN: %clang_cc1 -fsyntax-only %s -include-pch %t1.pch -DMACRO2=1 2>&1 | FileCheck %s
+
+#ifndef HEADER
+#define HEADER
+#else
+#define MACRO1 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO1' macro redefined
+// CHECK: <command line>{{.*}}previous definition is here
+#define MACRO2 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO2' macro redefined
+// CHECK: <command line>{{.*}}previous definition is here
+#endif
Index: clang/lib/Serialization/ASTWriter.cpp
===================================================================
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -4444,6 +4444,11 @@
bool ASTWriter::PreparePathForOutput(SmallVectorImpl<char> &Path) {
assert(Context && "should have context when outputting path");
+ // Leave special file names as they are.
+ StringRef PathStr(Path.data(), Path.size());
+ if (PathStr == "<built-in>" || PathStr == "<command line>")
+ return false;
+
bool Changed =
cleanPathForOutput(Context->getSourceManager().getFileManager(), Path);
Index: clang/lib/Serialization/ASTReader.cpp
===================================================================
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -654,6 +654,10 @@
SmallVector<StringRef, 4> ExistingMacroNames;
collectMacroDefinitions(ExistingPPOpts, ExistingMacros, &ExistingMacroNames);
+ // Use a line marker to enter the <command line> file, as the defines and
+ // undefines here will have come from the command line.
+ SuggestedPredefines += "# 1 \"<command line>\" 1\n";
+
for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) {
// Dig out the macro definition in the existing preprocessor options.
StringRef MacroName = ExistingMacroNames[I];
@@ -713,6 +717,10 @@
}
return true;
}
+
+ // Leave the <command line> file and return to <built-in>.
+ SuggestedPredefines += "# 1 \"<built-in>\" 2\n";
+
if (Validation == OptionValidateStrictMatches) {
// If strict matches are requested, don't tolerate any extra defines in
// the AST file that are missing on the command line.
@@ -1579,8 +1587,13 @@
auto Buffer = ReadBuffer(SLocEntryCursor, Name);
if (!Buffer)
return true;
- SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
- BaseOffset + Offset, IncludeLoc);
+ FileID FID = SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
+ BaseOffset + Offset, IncludeLoc);
+ if (Record[3]) {
+ SrcMgr::FileInfo &FileInfo =
+ const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile());
+ FileInfo.setHasLineDirectives();
+ }
break;
}
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
===================================================================
--- clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -687,8 +687,10 @@
const auto &SM = PP->getSourceManager();
auto DefLoc = MI->getDefinitionLoc();
- // Also avoid storing predefined macros like __DBL_MIN__.
+ // Also avoid storing macros that aren't defined in any file, i.e. predefined
+ // macros like __DBL_MIN__ and those defined on the command line.
if (SM.isWrittenInBuiltinFile(DefLoc) ||
+ SM.isWrittenInCommandLineFile(DefLoc) ||
Name->getName() == "__GCC_HAVE_DWARF2_CFI_ASM")
return true;
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits