Skip to content

Commit 61c3f3c

Browse files
author
Emery Conrad
committed
Treat overridden virtual files as file-less in GetDeclFile
LLVM now registers each interpreter input buffer as a virtual FileEntry with overridden contents. The no-FileEntry check no longer identifies interpreter inputs, so also return "" for content-overridden entries. Co-developed-with-the-help-of: Claude Code (Fable 5, human in the loop)
1 parent 53a1f56 commit 61c3f3c

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

‎lib/CppInterOp/CppInterOp.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,9 @@ std::string GetDeclFile(ConstDeclRef DRef) {
14151415
const clang::SourceManager& SM = D->getASTContext().getSourceManager();
14161416
Loc = SM.getExpansionLoc(Loc);
14171417
clang::OptionalFileEntryRef FE = SM.getFileEntryRefForID(SM.getFileID(Loc));
1418-
if (!FE)
1418+
// Interpreter input buffers are virtual files with overridden contents
1419+
// (input_line_N); they name no on-disk file, so report them as file-less.
1420+
if (!FE || SM.isFileOverridden(&FE->getFileEntry()))
14191421
return INTEROP_RETURN("");
14201422

14211423
llvm::StringRef Real = FE->getFileEntry().tryGetRealPathName();

‎unittests/CppInterOp/ScopeReflectionTest.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,8 +1734,9 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, ScopeReflection_DeclSourceAttribution) {
17341734

17351735
GetAllTopLevelDecls(code, Decls);
17361736

1737-
// Declarations parsed from a string have no FileEntry behind them, but their
1738-
// location is still valid, so the line is the one inside that buffer.
1737+
// Declarations parsed from a string live in a virtual input_line buffer,
1738+
// not an on-disk file; their location is still valid, so the line is the
1739+
// one inside that buffer.
17391740
EXPECT_EQ(Cpp::GetDeclFile(Decls[0]), "");
17401741
EXPECT_EQ(Cpp::GetDeclLine(Decls[0]), 1U);
17411742

0 commit comments

Comments
 (0)