diff --git a/rocclr/compiler/lib/backends/common/frontend_clang.cpp b/rocclr/compiler/lib/backends/common/frontend_clang.cpp index ebe35cafb7..1c7aa02e52 100644 --- a/rocclr/compiler/lib/backends/common/frontend_clang.cpp +++ b/rocclr/compiler/lib/backends/common/frontend_clang.cpp @@ -197,7 +197,8 @@ int amdcl::ClangOCLFrontend::compileCommand(const std::string& src) { } if (Options()->oVariables->FEGenSPIRV) { - std::ostringstream ss; + std::string s; + llvm::raw_string_ostream ss(s); std::string err; if (Options()->getLLVMArgc()) { diff --git a/rocclr/compiler/lib/backends/common/linker.cpp b/rocclr/compiler/lib/backends/common/linker.cpp index b63db511ce..58cd27eb38 100644 --- a/rocclr/compiler/lib/backends/common/linker.cpp +++ b/rocclr/compiler/lib/backends/common/linker.cpp @@ -504,19 +504,23 @@ checkAndFixAclBinaryTarget(llvm::Module* module, aclBinary* elf, bool translateSpirv(llvm::Module *&M, const std::string &DumpSpirv, const std::string &DumpLlvm){ - std::stringstream SS; + std::string S; + llvm::raw_string_ostream RSS(S); std::string Err; - if (!llvm::WriteSPIRV(M, SS, Err)) { + if (!llvm::WriteSPIRV(M, RSS, Err)) { llvm::errs() << "Fails to save LLVM as SPIR-V: " << Err << '\n'; return false; } if (!DumpSpirv.empty()) { std::ofstream OFS(DumpSpirv, std::ios::binary); - OFS << SS.str(); + OFS << RSS.str(); OFS.close(); } + RSS.flush(); + std::stringstream SS(S); + auto &Ctx = M->getContext(); delete M; M = nullptr; diff --git a/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp b/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp index ea525c8289..00fdf12e09 100644 --- a/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp +++ b/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp @@ -504,12 +504,12 @@ LLVMToSPIRV( } std::string spvImg; - std::stringstream ss(spvImg); + llvm::raw_string_ostream ss(spvImg); bool success = llvm::WriteSPIRV(llMod, ss, errMsg); if (opt->isDumpFlagSet(amd::option::DUMP_SPIRV)) { std::ofstream ofs(opt->getDumpFileName(".spv"), std::ios::binary); - ofs << spvImg; + ofs << ss.str(); ofs.close(); }