Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,15 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM,
bool MatchAnyLine = false;
if (!PH.Next("@")) {
ExpectedLoc = Pos;

// If an implicit directive is found in an incremental input buffer, allow
// it to match any other incremental input buffer
if (PP->isIncrementalProcessingEnabled()) {
StringRef CurrentBufferName =
SM.getBufferOrFake(SM.getFileID(Pos)).getBufferIdentifier();
if (CurrentBufferName.starts_with("input_line_"))
MatchAnyFileAndLine = true;
}
} else {
PH.Advance();
unsigned Line = 0;
Expand Down Expand Up @@ -552,10 +561,17 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM,
MatchAnyLine = true;
ExpectedLoc = SourceLocation();
} else {
// Lookup file via Preprocessor, like a #include.
OptionalFileEntryRef File =
PP->LookupFile(Pos, Filename, false, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr);
OptionalFileEntryRef File;
if (PP->isIncrementalProcessingEnabled() &&
Filename.starts_with("input_line_")) {
// Check if it came from the prompt
File = SM.getFileManager().getOptionalFileRef(Filename);
} else {
// Lookup file via Preprocessor, like a #include.
File =
PP->LookupFile(Pos, Filename, false, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr);
}
if (!File) {
Diags.Report(Pos.getLocWithOffset(PH.C - PH.Begin),
diag::err_verify_missing_file)
Expand Down
13 changes: 11 additions & 2 deletions clang/lib/Interpreter/IncrementalParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,17 @@ IncrementalParser::Parse(llvm::StringRef input) {
SourceLocation NewLoc = SM.getLocForStartOfFile(SM.getMainFileID());

// Create FileID for the current buffer.
FileID FID = SM.createFileID(std::move(MB), SrcMgr::C_User, /*LoadedID=*/0,
/*LoadedOffset=*/0, NewLoc);
FileID FID;
// Create FileEntry and FileID for the current buffer.
FileEntryRef FE = SM.getFileManager().getVirtualFileRef(
SourceName.str(), InputSize, 0 /* mod time*/);
SM.overrideFileContents(FE, std::move(MB));

// Ensure HeaderFileInfo exists before lookup to prevent assertion
HeaderSearch &HS = PP.getHeaderSearchInfo();
HS.getFileInfo(FE);

FID = SM.createFileID(FE, NewLoc, SrcMgr::C_User);

// NewLoc only used for diags.
if (PP.EnterSourceFile(FID, /*DirLookup=*/nullptr, NewLoc))
Expand Down
16 changes: 16 additions & 0 deletions clang/test/Interpreter/verify-diagnostics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// REQUIRES: host-supports-jit
// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc -verify

auto x = unknown_val;
// expected-error@input_line_4:1 {{use of undeclared identifier 'unknown_val'}}

int get_int() { return 42; }
char* ptr = get_int();
// expected-error@input_line_8:1 {{cannot initialize a variable of type 'char *' with an rvalue of type 'int'}}

// Verify without input_line_*
int y = ;
// expected-error {{expected expression}}

const char* a = "test"; // expected-note {{previous definition is here}}
const char* a = ""; // expected-error {{redefinition of 'a'}}
Loading