Skip to content

Commit dc5adca

Browse files
Emery Conradconrade-ctc
authored andcommitted
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 75b3f43 commit dc5adca

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
@@ -1315,7 +1315,9 @@ std::string GetDeclFile(ConstDeclRef DRef) {
13151315
const clang::SourceManager& SM = D->getASTContext().getSourceManager();
13161316
Loc = SM.getExpansionLoc(Loc);
13171317
clang::OptionalFileEntryRef FE = SM.getFileEntryRefForID(SM.getFileID(Loc));
1318-
if (!FE)
1318+
// Interpreter input buffers are virtual files with overridden contents
1319+
// (input_line_N); they name no on-disk file, so report them as file-less.
1320+
if (!FE || SM.isFileOverridden(&FE->getFileEntry()))
13191321
return INTEROP_RETURN("");
13201322

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

‎unittests/CppInterOp/ScopeReflectionTest.cpp‎

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

14031403
GetAllTopLevelDecls(code, Decls);
14041404

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

0 commit comments

Comments
 (0)