Skip to content

Commit d831b8e

Browse files
committed
[llvm] Fix invalidate use of BitcodeWriter API.
Use the WriteBitcodeToFile() function rather than BitcodeWriter::writeMethod() method to prevent a debugging assertion. Issue facebookresearch#514.
1 parent dae6434 commit d831b8e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

compiler_gym/envs/llvm/service/Benchmark.cc

+7-4
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ namespace {
3434

3535
BenchmarkHash getModuleHash(const llvm::Module& module) {
3636
BenchmarkHash hash;
37-
llvm::SmallVector<char, 256> buffer;
37+
Bitcode bitcode;
38+
3839
// Writing the entire bitcode to a buffer that is then discarded is
3940
// inefficient.
40-
llvm::BitcodeWriter writer(buffer);
41-
writer.writeModule(module, /*ShouldPreserveUseListOrder=*/false,
42-
/*Index=*/nullptr, /*GenerateHash=*/true, &hash);
41+
llvm::raw_svector_ostream ostream(bitcode);
42+
llvm::WriteBitcodeToFile(module, ostream,
43+
/*ShouldPreserveUseListOrder=*/false,
44+
/*Index=*/nullptr, /*GenerateHash=*/true, &hash);
45+
4346
return hash;
4447
}
4548

0 commit comments

Comments
 (0)