Index: clang/include/clang/Lex/PPCallbacks.h =================================================================== --- clang/include/clang/Lex/PPCallbacks.h +++ clang/include/clang/Lex/PPCallbacks.h @@ -305,6 +305,9 @@ virtual void PragmaAssumeNonNullEnd(PragmaIntroducer Introducer, SourceLocation Loc) {} + /// Callback invoked when a \#pragma once directive is read. + virtual void PragmaOnce(PragmaIntroducer Introducer, SourceLocation Loc) {} + /// Called by Preprocessor::HandleMacroExpandedIdentifier when a /// macro invocation is found. virtual void MacroExpands(const Token &MacroNameTok, @@ -627,6 +630,11 @@ Second->PragmaAssumeNonNullEnd(Introducer, Loc); } + void PragmaOnce(PragmaIntroducer Introducer, SourceLocation Loc) override { + First->PragmaOnce(Introducer, Loc); + Second->PragmaOnce(Introducer, Loc); + } + void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range, const MacroArgs *Args) override { First->MacroExpands(MacroNameTok, MD, Range, Args); Index: clang/include/clang/Lex/Preprocessor.h =================================================================== --- clang/include/clang/Lex/Preprocessor.h +++ clang/include/clang/Lex/Preprocessor.h @@ -2615,7 +2615,7 @@ void HandlePragmaDirective(PragmaIntroducer Introducer); public: - void HandlePragmaOnce(Token &OnceTok); + void HandlePragmaOnce(PragmaIntroducer Introducer, Token &OnceTok); void HandlePragmaMark(PragmaIntroducer Introducer, Token &MarkTok); void HandlePragmaPoison(); void HandlePragmaSystemHeader(Token &SysHeaderTok); Index: clang/lib/Lex/Pragma.cpp =================================================================== --- clang/lib/Lex/Pragma.cpp +++ clang/lib/Lex/Pragma.cpp @@ -403,7 +403,8 @@ } /// HandlePragmaOnce - Handle \#pragma once. OnceTok is the 'once'. -void Preprocessor::HandlePragmaOnce(Token &OnceTok) { +void Preprocessor::HandlePragmaOnce(PragmaIntroducer Introducer, + Token &OnceTok) { // Don't honor the 'once' when handling the primary source file, unless // this is a prefix to a TU, which indicates we're generating a PCH file, or // when the main file is a header (e.g. when -xc-header is provided on the @@ -416,6 +417,9 @@ // Get the current file lexer we're looking at. Ignore _Pragma 'files' etc. // Mark the file as a once-only file now. HeaderInfo.MarkFileIncludeOnce(getCurrentFileLexer()->getFileEntry()); + + if (Callbacks) + Callbacks->PragmaOnce(Introducer, OnceTok.getLocation()); } void Preprocessor::HandlePragmaMark(PragmaIntroducer Introducer, @@ -991,7 +995,7 @@ void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer, Token &OnceTok) override { PP.CheckEndOfDirective("pragma once"); - PP.HandlePragmaOnce(OnceTok); + PP.HandlePragmaOnce(Introducer, OnceTok); } };