Name the source file in empty split codegen parts (#2397)

This commit is contained in:
Chris Tate
2026-10-27 04:12:57 -05:00
committed by GitHub
2 changed files with 12 additions and 0 deletions
+2
View File
@@ -1241,6 +1241,7 @@ emitSplitCodegen(const EmitOptions &Options, Module &M, TargetMachine &Machine,
size_t Count = Options.Outputs.size();
std::optional<CodegenSplit> Split = splitForCodegen(M, Count);
std::string Identifier = M.getModuleIdentifier();
std::string SourceFileName = M.getSourceFileName();
Triple TargetTriple = M.getTargetTriple();
DataLayout Layout = M.getDataLayout();
std::vector<std::vector<SmallString<256>>> Temporaries(Count);
@@ -1274,6 +1275,7 @@ emitSplitCodegen(const EmitOptions &Options, Module &M, TargetMachine &Machine,
keepCodegenPart(*Part, Split->PartOf, I);
} else {
Part = std::make_unique<Module>(Identifier, Context);
Part->setSourceFileName(SourceFileName);
Part->setTargetTriple(TargetTriple);
Part->setDataLayout(Layout);
}
@@ -327,6 +327,16 @@ describe.runIf(helper !== null)("LLVM program partitions", () => {
const first = await readFile(parts[0]!);
const [single] = await emit(dir, source, { outputs: 1, optLevel: "2", name: "whole" });
expect(await readFile(single!)).toEqual(first);
// The empty parts name the source path, so they do not depend on the
// input's file name either.
const renamed = await emit(dir, source, {
outputs: 3,
optLevel: "2",
split: true,
name: "renamed",
});
for (let index = 0; index < parts.length; index++)
expect(await readFile(renamed[index]!)).toEqual(await readFile(parts[index]!));
});
test("split code generation requires several optimized outputs and no cache", async () => {