Skip to content

Commit df965db

Browse files
committed
[libafl_cc] Fix for changes to ArrayRef construct
Constructing an ArrayRef from a nullopt was deprecated in LLVM commit: `2529de5c935a ([ADT] Deprecate ArrayRef(std::nullopt) (#146011), 2025-06-27)` (First tagged in LLVM 21) Then removed in LLVM commit: `cfbb4cc31215 ([ADT] Remove ArrayRef(std::nullopt_t) (#165831), 2025-10-31)` (First tagged in LLVM 22) The LLVM authors recommend switching to the `{}` C++ syntax, so introduce that conditionally if and only if the LLVM version is greater than or equal to 21 and fall back to the previous nullopt workaround, otherwise
1 parent 031e496 commit df965db

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

crates/libafl_cc/src/common-llvm.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
#define HAVE_VECTOR_INTRINSICS 1
1111

1212
#include <optional>
13-
#if LLVM_VERSION_MAJOR >= 16
14-
// None constant being deprecated for LLVM-16, it is recommended
15-
// to use the std::nullopt_t type instead. (#1010)
16-
constexpr std::nullopt_t None = std::nullopt;
17-
#endif
1813

1914
// all llvm includes and friends
2015
#include "llvm/Support/CommandLine.h"
@@ -33,6 +28,23 @@ constexpr std::nullopt_t None = std::nullopt;
3328
#include "llvm/Passes/PassBuilder.h"
3429
#include "llvm/IR/PassManager.h"
3530

31+
#if LLVM_VERSION_MAJOR >= 21
32+
// None is only used in libafl_cc as the second parameter of MDNode::get()
33+
// that param is an ArrayRef, which can no longer be constructed with a
34+
// nullopt since LLVM 21+
35+
//
36+
// Keep these around to keep IWYU quiet
37+
#include "llvm/ADT/ArrayRef.h"
38+
namespace llvm {
39+
class Metadata;
40+
}
41+
inline constexpr llvm::ArrayRef<llvm::Metadata *> None{};
42+
#elif LLVM_VERSION_MAJOR >= 16
43+
// None constant being deprecated for LLVM-16, it is recommended
44+
// to use the std::nullopt_t type instead. (#1010)
45+
constexpr std::nullopt_t None = std::nullopt;
46+
#endif
47+
3648
#define FATAL(...) \
3749
do { \
3850
fprintf(stderr, "FATAL: " __VA_ARGS__); \

0 commit comments

Comments
 (0)