Skip to content

Commit 68bfb17

Browse files
authored
[Clang] Fix crash when building a module with CC_PRINT_HEADERS_FORMAT=json (#136227)
There is no main file when building a module, so the code in HeaderIncludesJSONCallback::EndOfMainFile() needs to check for that to avoid crashing.
1 parent c073c22 commit 68bfb17

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

clang/lib/Frontend/HeaderIncludeGen.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,11 @@ void HeaderIncludesCallback::FileSkipped(const FileEntryRef &SkippedFile, const
260260

261261
void HeaderIncludesJSONCallback::EndOfMainFile() {
262262
OptionalFileEntryRef FE = SM.getFileEntryRefForID(SM.getMainFileID());
263-
SmallString<256> MainFile(FE->getName());
264-
SM.getFileManager().makeAbsolutePath(MainFile);
263+
SmallString<256> MainFile;
264+
if (FE) {
265+
MainFile += FE->getName();
266+
SM.getFileManager().makeAbsolutePath(MainFile);
267+
}
265268

266269
std::string Str;
267270
llvm::raw_string_ostream OS(Str);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// RUN: %clang_cc1 -header-include-format=json -header-include-filtering=only-direct-system -header-include-file %t.txt -emit-module -x c -fmodules -fmodule-name=X %s -o /dev/null
2+
module X {}

0 commit comments

Comments
 (0)