diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index c89402fa137c0..b90c04776ff9e 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -466,6 +466,9 @@ SourceLocation Preprocessor::CheckEndOfDirective(StringRef DirType, bool EnableMacros, SmallVectorImpl *ExtraToks) { Token Tmp; + // Avoid use-of-uninitialized-memory for edge case(s) where there is no extra + // token to be parsed. + Tmp.startToken(); auto ReadNextTok = [this, ExtraToks, &Tmp](auto &&LexFn) { std::invoke(LexFn, this, Tmp); if (ExtraToks && Tmp.isNot(tok::eod)) diff --git a/clang/test/ClangScanDeps/p1689-suppress-warnings-no-eol.cppm b/clang/test/ClangScanDeps/p1689-suppress-warnings-no-eol.cppm new file mode 100644 index 0000000000000..79964100b20ad --- /dev/null +++ b/clang/test/ClangScanDeps/p1689-suppress-warnings-no-eol.cppm @@ -0,0 +1,25 @@ +// Test that there is no use-of-uninitialized memory when parsing '#include' in +// the last line, without a newline. +// +// Forked from p1689-suppress-warnings.cppm. + +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t + +// Test P1689 format - should NOT emit warnings +// RUN: clang-scan-deps -format=p1689 -- %clang++ -std=c++20 -I%t -c %t/mylib.cppm -o %t/mylib.o 2>&1 | FileCheck %s + +// CHECK-NOT: warning: +// CHECK: { +// CHECK: "revision" + +//--- header.h +// Empty header for testing + +//--- mylib.cppm +module; + +export module mylib; + +#include \ No newline at end of file