================
@@ -86,19 +125,48 @@ TEST(FeatureModulesTest, SuppressDiags) {
   }
 }
 
+TEST(FeatureModulesTest, BeforePPCallbacks) {
+  struct IncludeRecorder : public PPCallbacks {
+    IncludeRecorder(std::vector<std::string> &Includes) : Includes(Includes) {}
+
+    void InclusionDirective(SourceLocation, const Token &, StringRef FileName,
+                            bool, CharSourceRange, OptionalFileEntryRef,
+                            StringRef, StringRef, const clang::Module *, bool,
+                            SrcMgr::CharacteristicKind) override {
+      Includes.push_back(FileName.str());
+    }
+
+  private:
+    std::vector<std::string> &Includes;
+  };
+  std::vector<std::string> Includes;
+  auto Module = std::make_unique<TestModule>();
+  Module->BeforePPCallbacks = [&Includes](CompilerInstance &CI) {
+    // The preamble build sees this include directly. Register only during the
+    // main-file build to verify the callback sees the replayed event.
----------------
ArcsinX wrote:

> But where I get lost here is what does the preamble build see, in my naive 
> world it only looks at the includes themselves and not the main file at all,

This is right, but when processing the main file, we still need to observe the 
include directives, but we cannot do so directly due to preamble optimization. 
To address this, the preamble replay mechanism simulates real include directive 
processing by replaying preamble events and triggering preprocessor callbacks 
during the main file re-parse (even though the PCH is loaded instead).This test 
verifies that our extension to the feature module interface correctly exposes 
preprocessor events via the preamble replay mechanism within a feature module 
during main file processing. (ProgramAction == frontend::ParseSyntaxOnly 
indicates main file processing, whereas PCH generation uses the GeneratePCH 
action)

For clang-tidy this opens ability to use checks which relies on preprocessor 
events (e.g. llvm-header-guard)

https://github.com/llvm/llvm-project/pull/221054
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to