Skip to content

Commit 637276d

Browse files
authored
Fixes for LLVM 17 (as well as LLVM 16) (#1597)
1 parent e3a0945 commit 637276d

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

lib/bap_llvm/llvm_disasm.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,21 @@
3333
#include <limits>
3434
#include <typeinfo>
3535
#include <iostream>
36+
#if LLVM_VERSION_MAJOR >= 16
37+
#include <optional>
38+
#endif
3639

3740
#include "disasm.hpp"
3841
#include "llvm_disasm.h"
3942

4043
#include <llvm/MC/MCDisassembler/MCDisassembler.h>
4144

4245
#include <llvm/ADT/ArrayRef.h>
46+
#if LLVM_VERSION_MAJOR >= 17
47+
#include <llvm/TargetParser/Triple.h>
48+
#else
4349
#include <llvm/ADT/Triple.h>
50+
#endif
4451
#include <llvm/ADT/Twine.h>
4552

4653
template <typename T>
@@ -467,7 +474,12 @@ class llvm_disassembler : public disassembler_interface {
467474
} else if (p == is_true) {
468475
return true;
469476
} else {
477+
#if LLVM_VERSION_MAJOR >= 16
478+
// MCInstrDesc needs to know its own address to access some implicit tables.
479+
auto &d = ins_info->get(current.code);
480+
#else
470481
auto d = ins_info->get(current.code);
482+
#endif
471483
if (p == may_affect_control_flow) {
472484
return d.mayAffectControlFlow(mcinst, *reg_info);
473485
} else if (auto check = fun_of_pred(p)) {
@@ -655,7 +667,11 @@ struct create_llvm_disassembler : disasm_factory {
655667

656668
static void parse_environment_options(const char *prog_name, const char *env_var) {
657669
#if LLVM_VERSION_MAJOR >= 12
670+
#if LLVM_VERSION_MAJOR >= 16
671+
std::optional<std::string> env_value = llvm::sys::Process::GetEnv(llvm::StringRef(env_var));
672+
#else
658673
llvm::Optional<std::string> env_value = llvm::sys::Process::GetEnv(llvm::StringRef(env_var));
674+
#endif
659675
if (!env_value)
660676
return;
661677

lib/bap_llvm/llvm_loader_utils.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
#include <iomanip>
66
#include <iostream>
77

8+
#if LLVM_VERSION_MAJOR >= 17
9+
#include <llvm/TargetParser/Triple.h>
10+
#else
811
#include <llvm/ADT/Triple.h>
12+
#endif
913

1014
#include "llvm_error_or.hpp"
1115

lib/bap_llvm/llvm_primitives.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#include <iostream>
22

3+
#include <llvm/Config/llvm-config.h>
4+
#if LLVM_VERSION_MAJOR >= 17
5+
#include <llvm/TargetParser/Triple.h>
6+
#else
37
#include <llvm/ADT/Triple.h>
8+
#endif
49

510
#include "llvm_primitives.hpp"
611

0 commit comments

Comments
 (0)