From 19e70243775a6b32f35c37be8340f642ee00bc6a Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Sun, 18 Sep 2022 08:00:30 +0800 Subject: [PATCH] Fix some more deprecations with LLVM 16 (#4185) --- driver/cache.cpp | 16 ++++++++++++++++ driver/targetmachine.cpp | 7 ++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/driver/cache.cpp b/driver/cache.cpp index 886a1fabd0..bb5af90b1a 100644 --- a/driver/cache.cpp +++ b/driver/cache.cpp @@ -321,14 +321,30 @@ void outputIR2ObjRelevantCmdlineArgs(llvm::raw_ostream &hash_os) { hash_os << opts::getFeaturesStr(); hash_os << opts::floatABI; const auto relocModel = opts::getRelocModel(); +#if LDC_LLVM_VER >= 1600 + if (relocModel.has_value()) + hash_os << relocModel.value(); +#else if (relocModel.hasValue()) hash_os << relocModel.getValue(); +#endif const auto codeModel = opts::getCodeModel(); +#if LDC_LLVM_VER >= 1600 + if (codeModel.has_value()) + hash_os << codeModel.value(); +#else if (codeModel.hasValue()) hash_os << codeModel.getValue(); +#endif + const auto framePointerUsage = opts::framePointerUsage(); +#if LDC_LLVM_VER >= 1600 + if (framePointerUsage.has_value()) + hash_os << static_cast(framePointerUsage.value()); +#else if (framePointerUsage.hasValue()) hash_os << static_cast(framePointerUsage.getValue()); +#endif } // Output to `hash_os` all environment flags that influence object code output diff --git a/driver/targetmachine.cpp b/driver/targetmachine.cpp index c75538b5e7..3ded477670 100644 --- a/driver/targetmachine.cpp +++ b/driver/targetmachine.cpp @@ -426,7 +426,12 @@ createTargetMachine(const std::string targetTriple, const std::string arch, } // Handle cases where LLVM picks wrong default relocModel - if (!relocModel.hasValue()) { +#if LDC_LLVM_VER >= 1600 + if (relocModel.has_value()) {} +#else + if (relocModel.hasValue()) {} +#endif + else { if (triple.isOSDarwin()) { // Darwin defaults to PIC (and as of 10.7.5/LLVM 3.1-3.3, TLS use leads // to crashes for non-PIC code). LLVM doesn't handle this.