Skip to content

Commit 75aec47

Browse files
committed
llvm-wrapper: adapt for and LLVM API change
1 parent c372b14 commit 75aec47

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,12 @@ enum class LLVMRustCodeModel {
205205
None,
206206
};
207207

208-
static Optional<CodeModel::Model> fromRust(LLVMRustCodeModel Model) {
208+
#if LLVM_VERSION_LT(16, 0)
209+
static Optional<CodeModel::Model>
210+
#else
211+
static std::optional<CodeModel::Model>
212+
#endif
213+
fromRust(LLVMRustCodeModel Model) {
209214
switch (Model) {
210215
case LLVMRustCodeModel::Tiny:
211216
return CodeModel::Tiny;
@@ -638,7 +643,11 @@ LLVMRustOptimize(
638643
LLVMSelfProfileInitializeCallbacks(PIC,LlvmSelfProfiler,BeforePassCallback,AfterPassCallback);
639644
}
640645

646+
#if LLVM_VERSION_LT(16, 0)
641647
Optional<PGOOptions> PGOOpt;
648+
#else
649+
std::optional<PGOOptions> PGOOpt;
650+
#endif
642651
if (PGOGenPath) {
643652
assert(!PGOUsePath && !PGOSampleUsePath);
644653
PGOOpt = PGOOptions(PGOGenPath, "", "", PGOOptions::IRInstr,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
#include "llvm/Pass.h"
1818
#include "llvm/Bitcode/BitcodeWriter.h"
1919
#include "llvm/Support/Signals.h"
20+
#if LLVM_VERSION_LT(16, 0)
2021
#include "llvm/ADT/Optional.h"
22+
#endif
2123

2224
#include <iostream>
2325

@@ -708,7 +710,11 @@ enum class LLVMRustChecksumKind {
708710
SHA256,
709711
};
710712

713+
#if LLVM_VERSION_LT(16, 0)
711714
static Optional<DIFile::ChecksumKind> fromRust(LLVMRustChecksumKind Kind) {
715+
#else
716+
static std::optional<DIFile::ChecksumKind> fromRust(LLVMRustChecksumKind Kind) {
717+
#endif
712718
switch (Kind) {
713719
case LLVMRustChecksumKind::None:
714720
return None;
@@ -787,8 +793,18 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFile(
787793
const char *Filename, size_t FilenameLen,
788794
const char *Directory, size_t DirectoryLen, LLVMRustChecksumKind CSKind,
789795
const char *Checksum, size_t ChecksumLen) {
796+
797+
#if LLVM_VERSION_LT(16, 0)
790798
Optional<DIFile::ChecksumKind> llvmCSKind = fromRust(CSKind);
799+
#else
800+
std::optional<DIFile::ChecksumKind> llvmCSKind = fromRust(CSKind);
801+
#endif
802+
803+
#if LLVM_VERSION_LT(16, 0)
791804
Optional<DIFile::ChecksumInfo<StringRef>> CSInfo{};
805+
#else
806+
std::optional<DIFile::ChecksumInfo<StringRef>> CSInfo{};
807+
#endif
792808
if (llvmCSKind)
793809
CSInfo.emplace(*llvmCSKind, StringRef{Checksum, ChecksumLen});
794810
return wrap(Builder->createFile(StringRef(Filename, FilenameLen),

0 commit comments

Comments
 (0)