Revert "[Serialization] Place command line defines in the correct file"
authorFelipe de Azevedo Piovezan <fpiovezan@apple.com>
Fri, 24 Mar 2023 18:49:47 +0000 (14:49 -0400)
committerFelipe de Azevedo Piovezan <fpiovezan@apple.com>
Fri, 24 Mar 2023 18:49:47 +0000 (14:49 -0400)
This reverts commit 72073fc95cd4793a853925ddc8cc3fb2118808a5.

clang-tools-extra/clangd/index/SymbolCollector.cpp
clang/docs/ReleaseNotes.rst
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/PCH/macro-cmdline.c [deleted file]
clang/test/PCH/ms-pch-macro.c

index 519acee..3179810 100644 (file)
@@ -687,10 +687,8 @@ bool SymbolCollector::handleMacroOccurrence(const IdentifierInfo *Name,
 
   const auto &SM = PP->getSourceManager();
   auto DefLoc = MI->getDefinitionLoc();
-  // 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.
+  // Also avoid storing predefined macros like __DBL_MIN__.
   if (SM.isWrittenInBuiltinFile(DefLoc) ||
-      SM.isWrittenInCommandLineFile(DefLoc) ||
       Name->getName() == "__GCC_HAVE_DWARF2_CFI_ASM")
     return true;
 
index 526ea11..1f18de9 100644 (file)
@@ -177,8 +177,8 @@ Improvements to Clang's diagnostics
 - Diagnostic notes and fix-its are now generated for ``ifunc``/``alias`` attributes
   which point to functions whose names are mangled.
 - Diagnostics relating to macros on the command line of a preprocessed assembly
-  file or precompiled header are now reported as coming from the file
-  ``<command line>`` instead of ``<built-in>``.
+  file are now reported as coming from the file ``<command line>`` instead of
+  ``<built-in>``.
 - Clang constexpr evaluator now provides a more concise diagnostic when calling
   function pointer that is known to be null.
 - Clang now avoids duplicate warnings on unreachable ``[[fallthrough]];`` statements
index 6654df4..0273fa1 100644 (file)
@@ -654,10 +654,6 @@ static bool checkPreprocessorOptions(
   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];
@@ -717,10 +713,6 @@ static bool checkPreprocessorOptions(
     }
     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.
@@ -1587,13 +1579,8 @@ bool ASTReader::ReadSLocEntry(int ID) {
     auto Buffer = ReadBuffer(SLocEntryCursor, Name);
     if (!Buffer)
       return true;
-    FileID FID = SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
-                                        BaseOffset + Offset, IncludeLoc);
-    if (Record[3]) {
-      auto &FileInfo =
-          const_cast<SrcMgr::FileInfo &>(SourceMgr.getSLocEntry(FID).getFile());
-      FileInfo.setHasLineDirectives();
-    }
+    SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
+                           BaseOffset + Offset, IncludeLoc);
     break;
   }
 
index 31e44b5..d89ee4e 100644 (file)
@@ -4444,11 +4444,6 @@ void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) {
 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);
 
diff --git a/clang/test/PCH/macro-cmdline.c b/clang/test/PCH/macro-cmdline.c
deleted file mode 100644 (file)
index c4647f5..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-// 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 a512e66..3a8052e 100644 (file)
@@ -36,4 +36,4 @@ BAR bar = 17;
 // 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@2 {{definition of macro 'BAR' does not match definition in precompiled header}}
+// expected-warning@1 {{definition of macro 'BAR' does not match definition in precompiled header}}