1 From 94af090661d7c953c516c97a25ed053c744a0737 Mon Sep 17 00:00:00 2001
2 From: Alexey Sotkin <alexey.sotkin@intel.com>
3 Date: Mon, 18 Feb 2019 18:19:13 +0300
4 Subject: [PATCH] Align with modified llvm::writeSpirv API
7 common_clang.cpp | 29 +++++++++++++++++++++++++----
8 1 file changed, 25 insertions(+), 4 deletions(-)
10 diff --git a/common_clang.cpp b/common_clang.cpp
11 index eff1064..ee1ec9b 100644
12 --- a/common_clang.cpp
13 +++ b/common_clang.cpp
14 @@ -63,17 +63,18 @@ Copyright (c) Intel Corporation (2009-2017).
15 #define CL_OUT_OF_HOST_MEMORY -6
36 @@ -164,6 +165,25 @@ static void PrintCompileOptions(const char *pszOptions, const char *pszOptionsEx
40 +class SmallVectorBuffer : public std::streambuf
42 + // All memory management is delegated to llvm::SmallVectorImpl
43 + llvm::SmallVectorImpl<char> &OS;
45 + // Since we don't touch any pointer in streambuf(pbase, pptr, epptr) this is
46 + // the only method we need to override.
47 + virtual std::streamsize xsputn(const char *s, std::streamsize n) override {
48 + OS.append(s, s + n);
53 + SmallVectorBuffer() = delete;
54 + SmallVectorBuffer(const SmallVectorBuffer&) = delete;
55 + SmallVectorBuffer &operator=(const SmallVectorBuffer&) = delete;
56 + SmallVectorBuffer(llvm::SmallVectorImpl<char> &O) : OS(O) {}
59 extern "C" CC_DLL_EXPORT int
60 Compile(const char *pszProgramSource, const char **pInputHeaders,
61 unsigned int uiNumInputHeaders, const char **pInputHeadersNames,
62 @@ -300,7 +320,8 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
63 return CL_COMPILE_PROGRAM_FAILURE;
65 pResult->getIRBufferRef().clear();
66 - llvm::raw_svector_ostream OS(pResult->getIRBufferRef());
67 + SmallVectorBuffer StreamBuf(pResult->getIRBufferRef());
68 + std::ostream OS(&StreamBuf);
70 success = llvm::writeSpirv(M.get(), OS, Err);
71 err_ostream << Err.c_str();