Fix when built against latest LLVM (11)
LLVM changes certain function return types to Expected<T> instead of T.
This change adds an Unwrap that supports both cases, allowing the code
to build in both contexts.
Bug: b/171236524
Change-Id: I461ab440797695ca1e92d4827d6e6d8965dcf6b2
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/49468
Tested-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Reactor/LLVMJIT.cpp b/src/Reactor/LLVMJIT.cpp
index b4426a9..5aa28a0 100644
--- a/src/Reactor/LLVMJIT.cpp
+++ b/src/Reactor/LLVMJIT.cpp
@@ -466,6 +466,19 @@
}
};
+// As we must support different LLVM versions, add a generic Unwrap for functions that return Expected<T> or the actual T.
+// TODO(b/165000222): Remove after LLVM 11 upgrade
+template<typename T>
+auto &Unwrap(llvm::Expected<T> &&v)
+{
+ return v.get();
+}
+template<typename T>
+auto &Unwrap(T &&v)
+{
+ return v;
+}
+
// JITRoutine is a rr::Routine that holds a LLVM JIT session, compiler and
// object layer as each routine may require different target machine
// settings and no Reactor routine directly links against another.
@@ -492,7 +505,7 @@
, compileLayer(session, objectLayer, std::make_unique<llvm::orc::ConcurrentIRCompiler>(JITGlobals::get()->getTargetMachineBuilder(config.getOptimization().getLevel())))
, mangle(session, JITGlobals::get()->getDataLayout())
, ctx(std::make_unique<llvm::LLVMContext>())
- , dylib(session.createJITDylib("<routine>"))
+ , dylib(Unwrap(session.createJITDylib("<routine>")))
, addresses(count)
{