[PATCH] D106204: [Lex] Consider a PCH header-guarded even with #endif truncated

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 20 05:37:33 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfd2278505482: [Lex] Consider a PCH header-guarded even with #endif truncated (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D106204?vs=359503&id=360095#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106204/new/

https://reviews.llvm.org/D106204

Files:
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang/lib/Lex/Lexer.cpp


Index: clang/lib/Lex/Lexer.cpp
===================================================================
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -2793,6 +2793,11 @@
 
   if (PP->isRecordingPreamble() && PP->isInPrimaryFile()) {
     PP->setRecordedPreambleConditionalStack(ConditionalStack);
+    // If the preamble cuts off the end of a header guard, consider it guarded.
+    // The guard is valid for the preamble content itself, and for tools the
+    // most useful answer is "yes, this file has a header guard".
+    if (!ConditionalStack.empty())
+      MIOpt.ExitTopLevelConditional();
     ConditionalStack.clear();
   }
 
Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -667,7 +667,7 @@
   EXPECT_FALSE(mainIsGuarded(TU.build()));
 
   TU.Code = guard(";");
-  EXPECT_FALSE(mainIsGuarded(TU.build())); // FIXME: true
+  EXPECT_TRUE(mainIsGuarded(TU.build()));
 
   TU.Code = once(";");
   EXPECT_TRUE(mainIsGuarded(TU.build()));
@@ -768,7 +768,7 @@
   )cpp";
   AST = TU.build();
   EXPECT_THAT(*AST.getDiagnostics(), IsEmpty());
-  EXPECT_FALSE(mainIsGuarded(AST)); // FIXME: true
+  EXPECT_TRUE(mainIsGuarded(AST));
 
   // Guarded too late...
   TU.Code = R"cpp(
@@ -858,7 +858,7 @@
   TU.AdditionalFiles = {{"impl.h", Implementation}};
   auto AST = TU.build();
   EXPECT_THAT(*AST.getDiagnostics(), IsEmpty());
-  EXPECT_FALSE(mainIsGuarded(AST)); // FIXME: true
+  EXPECT_TRUE(mainIsGuarded(AST));
   // Slightly harder: the `#pragma once` is part of the preamble, and we
   // need to transfer it to the main file's HeaderFileInfo.
   TU.Code = once(Interface);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106204.360095.patch
Type: text/x-patch
Size: 1792 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210720/314d7a06/attachment.bin>


More information about the cfe-commits mailing list