Skip to content

Commit 417c0fa

Browse files
committed
Merge from 'main' to 'sycl-web' (24 commits)
CONFLICT (content): Merge conflict in clang/tools/clang-sycl-linker/CMakeLists.txt
2 parents a6733fd + 0d499f9 commit 417c0fa

File tree

101 files changed

+31351
-5431
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+31351
-5431
lines changed

clang/Maintainers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Sema
7272
Experimental new constant interpreter
7373
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7474
| Timm Bäder
75-
| tbaeder\@redhat.com (em), tbaeder (Phabricator), tbaederr (GitHub), tbaeder (Discourse), tbaeder (Discord)
75+
| tbaeder\@redhat.com (email), tbaeder (Phabricator), tbaederr (GitHub), tbaeder (Discourse), tbaeder (Discord)
7676
7777

7878
Modules & serialization

clang/docs/RealtimeSanitizer.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ projects. RTSan can be used to detect real-time violations, i.e. calls to method
1212
that are not safe for use in functions with deterministic run time requirements.
1313
RTSan considers any function marked with the ``[[clang::nonblocking]]`` attribute
1414
to be a real-time function. At run-time, if RTSan detects a call to ``malloc``,
15-
``free``, ``pthread_mutex_lock``, or anything else that could have a
15+
``free``, ``pthread_mutex_lock``, or anything else known to have a
1616
non-deterministic execution time in a function marked ``[[clang::nonblocking]]``
17-
RTSan raises an error.
17+
it raises an error.
1818

1919
RTSan performs its analysis at run-time but shares the ``[[clang::nonblocking]]``
2020
attribute with the :doc:`FunctionEffectAnalysis` system, which operates at

clang/lib/AST/ByteCode/Program.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,10 @@ Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty,
399399
}
400400

401401
// Arrays.
402-
if (const auto ArrayType = Ty->getAsArrayTypeUnsafe()) {
402+
if (const auto *ArrayType = Ty->getAsArrayTypeUnsafe()) {
403403
QualType ElemTy = ArrayType->getElementType();
404404
// Array of well-known bounds.
405-
if (auto CAT = dyn_cast<ConstantArrayType>(ArrayType)) {
405+
if (const auto *CAT = dyn_cast<ConstantArrayType>(ArrayType)) {
406406
size_t NumElems = CAT->getZExtSize();
407407
if (std::optional<PrimType> T = Ctx.classify(ElemTy)) {
408408
// Arrays of primitives.

clang/lib/Driver/ToolChains/PS4CPU.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
241241
// handled somewhere else.
242242
Args.ClaimAllArgs(options::OPT_w);
243243

244+
CmdArgs.push_back("-m");
245+
CmdArgs.push_back("elf_x86_64_fbsd");
246+
244247
CmdArgs.push_back(
245248
Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
246249

clang/test/Driver/ps5-linker.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
// Test that a target emulation is supplied to the linker
2+
3+
// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-EMU %s
4+
5+
// CHECK-EMU: {{ld(\.exe)?}}"
6+
// CHECK-EMU-SAME: "-m" "elf_x86_64_fbsd"
7+
18
// Test that PIE is the default for main components
29

310
// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-PIE %s

clang/tools/clang-sycl-linker/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
set(LLVM_LINK_COMPONENTS
22
${LLVM_TARGETS_TO_BUILD}
3+
<<<<<<< HEAD
34
Support
45
BinaryFormat
56
TargetParser
7+
=======
8+
BinaryFormat
9+
>>>>>>> 0d499f9043fed14ff8c7f9e24e19206c93aee5dd
610
Option
11+
Object
12+
TargetParser
13+
Support
714
)
815

916
set(LLVM_TARGET_DEFINITIONS SYCLLinkOpts.td)

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,19 @@ INTERCEPTOR(void *, valloc, SIZE_T size) {
467467
}
468468

469469
#if SANITIZER_INTERCEPT_ALIGNED_ALLOC
470+
471+
// In some cases, when targeting older Darwin versions, this warning may pop up.
472+
// Because we are providing a wrapper, the client is responsible to check
473+
// whether aligned_alloc is available, not us. We still succeed linking on an
474+
// old OS, because we are using a weak symbol (see aligned_alloc in
475+
// sanitizer_platform_interceptors.h)
476+
#pragma clang diagnostic push
477+
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
470478
INTERCEPTOR(void *, aligned_alloc, SIZE_T alignment, SIZE_T size) {
471479
__rtsan_notify_intercepted_call("aligned_alloc");
472480
return REAL(aligned_alloc)(alignment, size);
473481
}
482+
#pragma clang diagnostic pop
474483
#define RTSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC INTERCEPT_FUNCTION(aligned_alloc)
475484
#else
476485
#define RTSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC

compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,20 @@ TEST(TestRtsanInterceptors, VallocDiesWhenRealtime) {
122122
ExpectNonRealtimeSurvival(Func);
123123
}
124124

125-
#if SANITIZER_INTERCEPT_ALIGNED_ALLOC
125+
#if __has_builtin(__builtin_available) && SANITIZER_APPLE
126+
#define ALIGNED_ALLOC_AVAILABLE() (__builtin_available(macOS 10.15, *))
127+
#else
128+
// We are going to assume this is true until we hit systems where it isn't
129+
#define ALIGNED_ALLOC_AVAILABLE() (true)
130+
#endif
131+
126132
TEST(TestRtsanInterceptors, AlignedAllocDiesWhenRealtime) {
127-
auto Func = []() { EXPECT_NE(nullptr, aligned_alloc(16, 32)); };
128-
ExpectRealtimeDeath(Func, "aligned_alloc");
129-
ExpectNonRealtimeSurvival(Func);
133+
if (ALIGNED_ALLOC_AVAILABLE()) {
134+
auto Func = []() { EXPECT_NE(nullptr, aligned_alloc(16, 32)); };
135+
ExpectRealtimeDeath(Func, "aligned_alloc");
136+
ExpectNonRealtimeSurvival(Func);
137+
}
130138
}
131-
#endif
132139

133140
// free_sized and free_aligned_sized (both C23) are not yet supported
134141
TEST(TestRtsanInterceptors, FreeDiesWhenRealtime) {

compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,25 @@
8484
#define SI_NOT_MAC 1
8585
#endif
8686

87+
#if SANITIZER_APPLE
88+
# include <Availability.h>
89+
90+
// aligned_alloc was introduced in OSX 10.15
91+
// Linking will fail when using an older SDK
92+
# if defined(__MAC_10_15)
93+
// macOS 10.15 is greater than our minimal deployment target. To ensure we
94+
// generate a weak reference so the dylib continues to work on older
95+
// systems, we need to forward declare the intercepted function as "weak
96+
// imports".
97+
SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
98+
__sanitizer::usize __size);
99+
# define SI_MAC_SDK_10_15_AVAILABLE 1
100+
# else
101+
# define SI_MAC_SDK_10_15_AVAILABLE 0
102+
# endif // defined(__MAC_10_15)
103+
104+
#endif // SANITIZER_APPLE
105+
87106
#if SANITIZER_IOS
88107
#define SI_IOS 1
89108
#else
@@ -500,7 +519,8 @@
500519
#define SANITIZER_INTERCEPT_PVALLOC (SI_GLIBC || SI_ANDROID)
501520
#define SANITIZER_INTERCEPT_CFREE (SI_GLIBC && !SANITIZER_RISCV64)
502521
#define SANITIZER_INTERCEPT_REALLOCARRAY SI_POSIX
503-
#define SANITIZER_INTERCEPT_ALIGNED_ALLOC (!SI_MAC)
522+
#define SANITIZER_INTERCEPT_ALIGNED_ALLOC \
523+
(!SI_MAC || SI_MAC_SDK_10_15_AVAILABLE)
504524
#define SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE (!SI_MAC && !SI_NETBSD)
505525
#define SANITIZER_INTERCEPT_MCHECK_MPROBE SI_LINUX_NOT_ANDROID
506526
#define SANITIZER_INTERCEPT_WCSLEN 1

flang/lib/Optimizer/Transforms/CUFAddConstructor.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
#include "flang/Optimizer/Builder/Runtime/RTBuilder.h"
1212
#include "flang/Optimizer/Builder/Todo.h"
1313
#include "flang/Optimizer/CodeGen/Target.h"
14+
#include "flang/Optimizer/CodeGen/TypeConverter.h"
1415
#include "flang/Optimizer/Dialect/CUF/CUFOps.h"
1516
#include "flang/Optimizer/Dialect/FIRAttr.h"
1617
#include "flang/Optimizer/Dialect/FIRDialect.h"
1718
#include "flang/Optimizer/Dialect/FIROps.h"
1819
#include "flang/Optimizer/Dialect/FIROpsSupport.h"
20+
#include "flang/Optimizer/Dialect/FIRType.h"
1921
#include "flang/Optimizer/Support/DataLayout.h"
2022
#include "flang/Optimizer/Transforms/CUFCommon.h"
2123
#include "flang/Runtime/CUDA/registration.h"
@@ -84,6 +86,8 @@ struct CUFAddConstructor
8486
auto registeredMod = builder.create<cuf::RegisterModuleOp>(
8587
loc, llvmPtrTy, mlir::SymbolRefAttr::get(ctx, gpuMod.getName()));
8688

89+
fir::LLVMTypeConverter typeConverter(mod, /*applyTBAA=*/false,
90+
/*forceUnifiedTBAATree=*/false, *dl);
8791
// Register kernels
8892
for (auto func : gpuMod.getOps<mlir::gpu::GPUFuncOp>()) {
8993
if (func.isKernel()) {
@@ -115,17 +119,25 @@ struct CUFAddConstructor
115119
fir::factory::createStringLiteral(builder, loc, gblNameStr));
116120

117121
// Global variable size
118-
auto sizeAndAlign = fir::getTypeSizeAndAlignmentOrCrash(
119-
loc, globalOp.getType(), *dl, kindMap);
120-
auto size =
121-
builder.createIntegerConstant(loc, idxTy, sizeAndAlign.first);
122+
std::optional<uint64_t> size;
123+
if (auto boxTy =
124+
mlir::dyn_cast<fir::BaseBoxType>(globalOp.getType())) {
125+
mlir::Type structTy = typeConverter.convertBoxTypeAsStruct(boxTy);
126+
size = dl->getTypeSizeInBits(structTy) / 8;
127+
}
128+
if (!size) {
129+
size = fir::getTypeSizeAndAlignmentOrCrash(loc, globalOp.getType(),
130+
*dl, kindMap)
131+
.first;
132+
}
133+
auto sizeVal = builder.createIntegerConstant(loc, idxTy, *size);
122134

123135
// Global variable address
124136
mlir::Value addr = builder.create<fir::AddrOfOp>(
125137
loc, globalOp.resultType(), globalOp.getSymbol());
126138

127139
llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments(
128-
builder, loc, fTy, registeredMod, addr, gblName, size)};
140+
builder, loc, fTy, registeredMod, addr, gblName, sizeVal)};
129141
builder.create<fir::CallOp>(loc, func, args);
130142
} break;
131143
case cuf::DataAttribute::Managed:

flang/test/Fir/CUDA/cuda-constructor-2.f90

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<!llvm.ptr, dense<64> : vector<4xi64>>, #dlti.dl_entry<!llvm.ptr<271>, dense<32> : vector<4xi64>>, #dlti.dl_entry<!llvm.ptr<270>, dense<32> : vector<4xi64>>, #dlti.dl_entry<f128, dense<128> : vector<2xi64>>, #dlti.dl_entry<f64, dense<64> : vector<2xi64>>, #dlti.dl_entry<f80, dense<128> : vector<2xi64>>, #dlti.dl_entry<f16, dense<16> : vector<2xi64>>, #dlti.dl_entry<i32, dense<32> : vector<2xi64>>, #dlti.dl_entry<i16, dense<16> : vector<2xi64>>, #dlti.dl_entry<i128, dense<128> : vector<2xi64>>, #dlti.dl_entry<i8, dense<8> : vector<2xi64>>, #dlti.dl_entry<!llvm.ptr<272>, dense<64> : vector<4xi64>>, #dlti.dl_entry<i64, dense<64> : vector<2xi64>>, #dlti.dl_entry<i1, dense<8> : vector<2xi64>>, #dlti.dl_entry<"dlti.endianness", "little">, #dlti.dl_entry<"dlti.stack_alignment", 128 : i64>>, fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", gpu.container_module, llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", llvm.ident = "flang version 20.0.0 (https://github.com/llvm/llvm-project.git cae351f3453a0a26ec8eb2ddaf773c24a29d929e)", llvm.target_triple = "x86_64-unknown-linux-gnu"} {
44

55
fir.global @_QMmtestsEn(dense<[3, 4, 5, 6, 7]> : tensor<5xi32>) {data_attr = #cuf.cuda<device>} : !fir.array<5xi32>
6+
fir.global @_QMmtestsEndev {data_attr = #cuf.cuda<device>} : !fir.box<!fir.heap<!fir.array<?xi32>>> {
7+
%c0 = arith.constant 0 : index
8+
%0 = fir.zero_bits !fir.heap<!fir.array<?xi32>>
9+
%1 = fircg.ext_embox %0(%c0) {allocator_idx = 2 : i32} : (!fir.heap<!fir.array<?xi32>>, index) -> !fir.box<!fir.heap<!fir.array<?xi32>>>
10+
fir.has_value %1 : !fir.box<!fir.heap<!fir.array<?xi32>>>
11+
}
612

713
gpu.module @cuda_device_mod [#nvvm.target] {
814
}
@@ -18,5 +24,9 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<!llvm.ptr, dense<
1824
// CHECK-DAG: %[[VAR_ADDR2:.*]] = fir.convert %[[VAR_ADDR]] : (!fir.ref<!fir.array<5xi32>>) -> !fir.ref<i8>
1925
// CHECK-DAG: %[[VAR_NAME2:.*]] = fir.convert %[[VAR_NAME]] : (!fir.ref<!fir.char<1,12>>) -> !fir.ref<i8>
2026
// CHECK-DAG: %[[CST:.*]] = arith.constant 20 : index
21-
// CHECK-DAG %[[CST2:.*]] = fir.convert %[[CST]] : (index) -> i64
22-
// CHECK fir.call @_FortranACUFRegisterVariable(%[[MODULE2]], %[[VAR_ADDR2]], %[[VAR_NAME2]], %[[CST2]]) : (!fir.ref<!fir.llvm_ptr<i8>>, !fir.ref<i8>, !fir.ref<i8>, i64) -> none
27+
// CHECK-DAG: %[[CST2:.*]] = fir.convert %[[CST]] : (index) -> i64
28+
// CHECK-DAG: fir.call @_FortranACUFRegisterVariable(%[[MODULE2]], %[[VAR_ADDR2]], %[[VAR_NAME2]], %[[CST2]]) : (!fir.ref<!fir.llvm_ptr<i8>>, !fir.ref<i8>, !fir.ref<i8>, i64) -> none
29+
// CHECK-DAG: %[[BOX:.*]] = fir.address_of(@_QMmtestsEndev) : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
30+
// CHECK-DAG: %[[BOXREF:.*]] = fir.convert %[[BOX]] : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) -> !fir.ref<i8>
31+
// CHECK-DAG: fir.call @_FortranACUFRegisterVariable(%[[MODULE:.*]], %[[BOXREF]], %{{.*}}, %{{.*}})
32+
//

flang/test/Fir/CUDA/cuda-register-func.fir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: fir-opt --cuf-add-constructor %s | FileCheck %s
22

3-
module attributes {gpu.container_module} {
3+
module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<!llvm.ptr, dense<64> : vector<4xi64>>, #dlti.dl_entry<!llvm.ptr<271>, dense<32> : vector<4xi64>>, #dlti.dl_entry<!llvm.ptr<270>, dense<32> : vector<4xi64>>, #dlti.dl_entry<f128, dense<128> : vector<2xi64>>, #dlti.dl_entry<f64, dense<64> : vector<2xi64>>, #dlti.dl_entry<f80, dense<128> : vector<2xi64>>, #dlti.dl_entry<f16, dense<16> : vector<2xi64>>, #dlti.dl_entry<i32, dense<32> : vector<2xi64>>, #dlti.dl_entry<i16, dense<16> : vector<2xi64>>, #dlti.dl_entry<i128, dense<128> : vector<2xi64>>, #dlti.dl_entry<i8, dense<8> : vector<2xi64>>, #dlti.dl_entry<!llvm.ptr<272>, dense<64> : vector<4xi64>>, #dlti.dl_entry<i64, dense<64> : vector<2xi64>>, #dlti.dl_entry<i1, dense<8> : vector<2xi64>>, #dlti.dl_entry<"dlti.endianness", "little">, #dlti.dl_entry<"dlti.stack_alignment", 128 : i64>>, fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", gpu.container_module, llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", llvm.ident = "flang version 20.0.0 (https://github.com/llvm/llvm-project.git cae351f3453a0a26ec8eb2ddaf773c24a29d929e)", llvm.target_triple = "x86_64-unknown-linux-gnu"} {
44
gpu.module @cuda_device_mod {
55
gpu.func @_QPsub_device1() kernel {
66
gpu.return

libc/utils/MPFRWrapper/MPFRUtils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ class MPFRNumber {
262262

263263
int d = mpz_tstbit(integer, 0);
264264
mpfr_set_si(result.value, d ? -1 : 1, mpfr_rounding);
265+
mpz_clear(integer);
265266
return result;
266267
}
267268

libcxx/include/__config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <__configuration/abi.h>
1515
#include <__configuration/availability.h>
1616
#include <__configuration/compiler.h>
17+
#include <__configuration/language.h>
1718
#include <__configuration/platform.h>
1819

1920
#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER

libcxxabi/src/demangle/cp-to-llvm.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if [[ ! -d "$LLVM_DEMANGLE_DIR" ]]; then
1818
exit 1
1919
fi
2020

21-
read -p "This will overwrite the copies of $FILES in $LLVM_DEMANGLE_DIR; are you sure? [y/N]" -n 1 -r ANSWER
21+
read -p "This will overwrite the copies of $HDRS in $LLVM_DEMANGLE_DIR; are you sure? [y/N]" -n 1 -r ANSWER
2222
echo
2323

2424
if [[ $ANSWER =~ ^[Yy]$ ]]; then

lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ Expected<std::string> python::As<std::string>(Expected<PythonObject> &&obj) {
7171
}
7272

7373
static bool python_is_finalizing() {
74-
#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 13) || (PY_MAJOR_VERSION > 3)
74+
#if PY_VERSION_HEX >= 0x030d0000
7575
return Py_IsFinalizing();
76-
#elif PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 7
77-
return _Py_Finalizing != nullptr;
78-
#else
76+
#elif PY_VERSION_HEX >= 0x03070000
7977
return _Py_IsFinalizing();
78+
#else
79+
return _Py_Finalizing != nullptr;
8080
#endif
8181
}
8282

@@ -810,7 +810,7 @@ bool PythonCallable::Check(PyObject *py_obj) {
810810
return PyCallable_Check(py_obj);
811811
}
812812

813-
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
813+
#if PY_VERSION_HEX >= 0x03030000
814814
static const char get_arg_info_script[] = R"(
815815
from inspect import signature, Parameter, ismethod
816816
from collections import namedtuple
@@ -839,7 +839,7 @@ Expected<PythonCallable::ArgInfo> PythonCallable::GetArgInfo() const {
839839
if (!IsValid())
840840
return nullDeref();
841841

842-
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
842+
#if PY_VERSION_HEX >= 0x03030000
843843

844844
// no need to synchronize access to this global, we already have the GIL
845845
static PythonScript get_arg_info(get_arg_info_script);

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ extern "C" PyObject *PyInit__lldb(void);
7171
#define LLDB_USE_PYTHON_SET_INTERRUPT 0
7272
#else
7373
// PyErr_SetInterrupt was introduced in 3.2.
74-
#define LLDB_USE_PYTHON_SET_INTERRUPT \
75-
(PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 2) || (PY_MAJOR_VERSION > 3)
74+
#define LLDB_USE_PYTHON_SET_INTERRUPT PY_VERSION_HEX >= 0x03020000
7675
#endif
7776

7877
static ScriptInterpreterPythonImpl *GetPythonInterpreter(Debugger &debugger) {
@@ -92,7 +91,7 @@ namespace {
9291
struct InitializePythonRAII {
9392
public:
9493
InitializePythonRAII() {
95-
#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 8) || (PY_MAJOR_VERSION > 3)
94+
#if PY_VERSION_HEX >= 0x03080000
9695
PyConfig config;
9796
PyConfig_InitPythonConfig(&config);
9897
#endif
@@ -109,7 +108,7 @@ struct InitializePythonRAII {
109108
return spec.GetPath();
110109
}();
111110
if (!g_python_home.empty()) {
112-
#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 8) || (PY_MAJOR_VERSION > 3)
111+
#if PY_VERSION_HEX >= 0x03080000
113112
PyConfig_SetBytesString(&config, &config.home, g_python_home.c_str());
114113
#else
115114
size_t size = 0;
@@ -143,7 +142,7 @@ struct InitializePythonRAII {
143142
PyImport_AppendInittab("_lldb", LLDBSwigPyInit);
144143
}
145144

146-
#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 8) || (PY_MAJOR_VERSION > 3)
145+
#if PY_VERSION_HEX >= 0x03080000
147146
config.install_signal_handlers = 0;
148147
Py_InitializeFromConfig(&config);
149148
PyConfig_Clear(&config);
@@ -152,7 +151,7 @@ struct InitializePythonRAII {
152151
// Python < 3.2 and Python >= 3.2 reversed the ordering requirements for
153152
// calling `Py_Initialize` and `PyEval_InitThreads`. < 3.2 requires that you
154153
// call `PyEval_InitThreads` first, and >= 3.2 requires that you call it last.
155-
#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 2)
154+
#if PY_VERSION_HEX >= 0x03020000
156155
Py_InitializeEx(0);
157156
InitializeThreadsPrivate();
158157
#else
@@ -182,15 +181,15 @@ struct InitializePythonRAII {
182181
// would always return `true` and `PyGILState_Ensure/Release` flow would be
183182
// executed instead of unlocking GIL with `PyEval_SaveThread`. When
184183
// an another thread calls `PyGILState_Ensure` it would get stuck in deadlock.
185-
#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 7) || (PY_MAJOR_VERSION > 3)
184+
#if PY_VERSION_HEX >= 0x03070000
186185
// The only case we should go further and acquire the GIL: it is unlocked.
187186
if (PyGILState_Check())
188187
return;
189188
#endif
190189

191190
// `PyEval_ThreadsInitialized` was deprecated in Python 3.9 and removed in
192191
// Python 3.13. It has been returning `true` always since Python 3.7.
193-
#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 9) || (PY_MAJOR_VERSION < 3)
192+
#if PY_VERSION_HEX < 0x03090000
194193
if (PyEval_ThreadsInitialized()) {
195194
#else
196195
if (true) {
@@ -204,7 +203,7 @@ struct InitializePythonRAII {
204203

205204
// `PyEval_InitThreads` was deprecated in Python 3.9 and removed in
206205
// Python 3.13.
207-
#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 9) || (PY_MAJOR_VERSION < 3)
206+
#if PY_VERSION_HEX < 0x03090000
208207
return;
209208
}
210209

lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ static llvm::Expected<bool> *g_fcxx_modules_workaround [[maybe_unused]];
4747

4848
// Include python for non windows machines
4949
#include <Python.h>
50+
51+
// Provide a meaningful diagnostic error if someone tries to compile this file
52+
// with a version of Python we don't support.
53+
static_assert(PY_VERSION_HEX >= 0x03000000,
54+
"LLDB requires at least Python 3.0");
5055
#endif
5156

5257
#endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_LLDB_PYTHON_H

lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ class NewStyle(object):
760760
EXPECT_EQ(arginfo.get().max_positional_args, 3u);
761761
}
762762

763-
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
763+
#if PY_VERSION_HEX >= 0x03030000
764764

765765
// the old implementation of GetArgInfo just doesn't work on builtins.
766766

0 commit comments

Comments
 (0)