diff --git a/clang-tools-extra/pp-trace/PPCallbacksTracker.h b/clang-tools-extra/pp-trace/PPCallbacksTracker.h --- a/clang-tools-extra/pp-trace/PPCallbacksTracker.h +++ b/clang-tools-extra/pp-trace/PPCallbacksTracker.h @@ -135,6 +135,7 @@ StringRef Str) override; void PragmaExecCharsetPop(PragmaIntroducer Introducer, SourceLocation Loc) override; + void PragmaOnce(PragmaIntroducer Introducer, SourceLocation Loc) override; void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range, const MacroArgs *Args) override; void MacroDefined(SourceLocation HashLoc, const Token &MacroNameTok, diff --git a/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp b/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp --- a/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp +++ b/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp @@ -337,6 +337,13 @@ appendArgument("Loc", Loc); } +/// Callback invoked when a \#pragma once directive is read. +void PPCallbacksTracker::PragmaOnce(PragmaIntroducer Introducer, SourceLocation Loc) { + beginCallback("PragmaOnce"); + appendArgument("Introducer", Introducer); + appendArgument("Loc", Loc); +} + // Called by Preprocessor::HandleMacroExpandedIdentifier when a // macro invocation is found. void PPCallbacksTracker::MacroExpands(const Token &MacroNameTok, diff --git a/clang-tools-extra/test/pp-trace/pp-trace-pragma-general.cpp b/clang-tools-extra/test/pp-trace/pp-trace-pragma-general.cpp --- a/clang-tools-extra/test/pp-trace/pp-trace-pragma-general.cpp +++ b/clang-tools-extra/test/pp-trace/pp-trace-pragma-general.cpp @@ -1,4 +1,4 @@ -// RUN: pp-trace -callbacks '*,-FileChanged,-MacroDefined' %s -- | FileCheck --strict-whitespace %s +// RUN: pp-trace -callbacks '*,-FileChanged,-MacroDefined' -extra-arg-before=-xc++-header %s -- | FileCheck --strict-whitespace %s #pragma clang diagnostic push #pragma clang diagnostic pop @@ -19,6 +19,8 @@ { } } +#pragma once + // CHECK: --- // CHECK-NEXT: - Callback: PragmaDirective // CHECK-NEXT: Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:3:1", Kind: PIK_HashPragma} @@ -114,5 +116,10 @@ // CHECK-NEXT: Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:18:1", Kind: PIK_HashPragma} // CHECK-NEXT: Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:18:23" // CHECK-NEXT: DebugType: captured +// CHECK-NEXT: - Callback: PragmaDirective +// CHECK-NEXT: Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:22:1", Kind: PIK_HashPragma} +// CHECK-NEXT: - Callback: PragmaOnce +// CHECK-NEXT: Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:22:1", Kind: PIK_HashPragma} +// CHECK-NEXT: Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:22:9" // CHECK-NEXT: - Callback: EndOfMainFile // CHECK-NEXT: ...