@@ -83,13 +83,14 @@ bool checkAndConsumeModuleDecl(const SourceManager &SM, Lexer &Lex,
8383 return Matched;
8484}
8585
86- // Returns the offset after header guard directives and any comments
87- // before/after header guards (e.g. #ifndef/#define pair, #pragma once). If no
88- // header guard is present in the code, this will return the offset after
89- // skipping all comments from the start of the code.
90- unsigned getOffsetAfterHeaderGuardsAndComments (StringRef FileName,
91- StringRef Code,
92- const IncludeStyle &Style) {
86+ // If file does not use modules, returns the offset after header guard
87+ // directives and any comments before/after header guards (e.g.
88+ // `#ifndef/#define` pair, `#pragma once`). If no header guard is present in the
89+ // code, this will return the offset after skipping all comments from the start
90+ // of the code. If modules are in use, the offset will be in the global module
91+ // fragment.
92+ unsigned getMinHeaderInsertionOffset (StringRef FileName, StringRef Code,
93+ const IncludeStyle &Style) {
9394 // \p Consume returns location after header guard or 0 if no header guard is
9495 // found.
9596 auto ConsumeHeaderGuardAndComment =
@@ -300,8 +301,7 @@ const llvm::Regex HeaderIncludes::IncludeRegex(IncludeRegexPattern);
300301HeaderIncludes::HeaderIncludes (StringRef FileName, StringRef Code,
301302 const IncludeStyle &Style)
302303 : FileName(FileName), Code(Code), FirstIncludeOffset(-1 ),
303- MinInsertOffset (
304- getOffsetAfterHeaderGuardsAndComments (FileName, Code, Style)),
304+ MinInsertOffset (getMinHeaderInsertionOffset(FileName, Code, Style)),
305305 MaxInsertOffset(MinInsertOffset +
306306 getMaxHeaderInsertionOffset (
307307 FileName, Code.drop_front(MinInsertOffset), Style)),
0 commit comments