Skip to content

Commit 9422da5

Browse files
committed
Add test and introduce -host-support-out-of-process-jit flag
1 parent 05943c9 commit 9422da5

File tree

3 files changed

+116
-1
lines changed

3 files changed

+116
-1
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// REQUIRES: host-supports-jit, host-supports-out-of-process-jit, x86_64-linux
2+
3+
// RUN: cat %s | clang-repl -oop-executor -orc-runtime | FileCheck %s
4+
5+
extern "C" int printf(const char *, ...);
6+
7+
int intVar = 0;
8+
double doubleVar = 3.14;
9+
%undo
10+
double doubleVar = 2.71;
11+
12+
auto r1 = printf("intVar = %d\n", intVar);
13+
// CHECK: intVar = 0
14+
auto r2 = printf("doubleVar = %.2f\n", doubleVar);
15+
// CHECK: doubleVar = 2.71
16+
17+
// Test redefinition with inline and static functions.
18+
int add(int a, int b, int c) { return a + b + c; }
19+
%undo // Revert to the initial version of add
20+
inline int add(int a, int b) { return a + b; }
21+
22+
auto r3 = printf("add(1, 2) = %d\n", add(1, 2));
23+
// CHECK-NEXT: add(1, 2) = 3
24+
25+
// Test inline and lambda functions with variations.
26+
inline int square(int x) { return x * x; }
27+
auto lambdaSquare = [](int x) { return x * x; };
28+
auto lambdaMult = [](int a, int b) { return a * b; };
29+
30+
auto r4 = printf("square(4) = %d\n", square(4));
31+
// CHECK-NEXT: square(4) = 16
32+
auto lambda_r1 = printf("lambdaSquare(5) = %d\n", lambdaSquare(5));
33+
// CHECK-NEXT: lambdaSquare(5) = 25
34+
auto lambda_r2 = printf("lambdaMult(2, 3) = %d\n", lambdaMult(2, 3));
35+
// CHECK-NEXT: lambdaMult(2, 3) = 6
36+
37+
%undo // Undo previous lambda assignments
38+
auto lambda_r3 = lambdaMult(3, 4); // Should fail or revert to the original lambda
39+
40+
// Test weak and strong symbol linkage.
41+
int __attribute__((weak)) weakFunc() { return 42; }
42+
int strongFunc() { return 100; }
43+
%undo // Revert the weak function
44+
45+
auto r5 = printf("weakFunc() = %d\n", weakFunc());
46+
// CHECK: weakFunc() = 42
47+
auto r6 = printf("strongFunc() = %d\n", strongFunc());
48+
// CHECK-NEXT: strongFunc() = 100
49+
50+
// Weak variable linkage with different types.
51+
int varA = 20;
52+
static __typeof(varA) weakVarA __attribute__((__weakref__("varA")));
53+
char charVar = 'c';
54+
static __typeof(charVar) weakCharVar __attribute__((__weakref__("charVar")));
55+
auto r7 = printf("weakVarA = %d\n", weakVarA);
56+
// CHECK: weakVarA = 20
57+
auto r8 = printf("weakCharVar = %c\n", weakCharVar);
58+
// CHECK-NEXT: weakCharVar = c
59+
60+
// Test complex lambdas with captures.
61+
int captureVar = 5;
62+
auto captureLambda = [](int x) { return x + captureVar; };
63+
int result1 = captureLambda(10);
64+
%undo // Undo capture lambda
65+
66+
auto r9 = printf("captureLambda(10) = %d\n", result1);
67+
// CHECK: captureLambda(10) = 15
68+
69+
// Multiline statement test with arithmetic operations.
70+
int sum = \
71+
5 + \
72+
10;
73+
int prod = sum * 2;
74+
auto r10 = printf("sum = %d, prod = %d\n", sum, prod);
75+
// CHECK: sum = 15, prod = 30
76+
77+
// Test multiline functions and macro behavior.
78+
#define MULTIPLY(a, b) ((a) * (b))
79+
80+
int complexFunc(int x) \
81+
{ \
82+
return MULTIPLY(x, 2) + x; \
83+
}
84+
85+
auto r11 = printf("complexFunc(5) = %d\n", complexFunc(5));
86+
// CHECK: complexFunc(5) = 15
87+
88+
%quit

clang/test/lit.cfg.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,30 @@
116116
if config.clang_examples:
117117
config.available_features.add("examples")
118118

119+
def have_host_out_of_process_jit_feature_support():
120+
clang_repl_exe = lit.util.which("clang-repl", config.clang_tools_dir)
121+
122+
if not clang_repl_exe:
123+
return False
124+
125+
testcode = b'\n'.join([
126+
b"int i = 0;",
127+
b"%quit"
128+
])
129+
130+
try:
131+
clang_repl_cmd = subprocess.run(
132+
[clang_repl_exe, "-orc-runtime", "-oop-executor"],
133+
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
134+
input=testcode
135+
)
136+
except OSError:
137+
return False
138+
139+
if clang_repl_cmd.returncode == 0:
140+
return True
141+
142+
return False
119143

120144
def have_host_jit_feature_support(feature_name):
121145
clang_repl_exe = lit.util.which("clang-repl", config.clang_tools_dir)
@@ -169,6 +193,9 @@ def have_host_clang_repl_cuda():
169193
if have_host_clang_repl_cuda():
170194
config.available_features.add('host-supports-cuda')
171195

196+
if have_host_out_of_process_jit_feature_support():
197+
config.available_features.add('host-supports-out-of-process-jit')
198+
172199
if config.clang_staticanalyzer:
173200
config.available_features.add("staticanalyzer")
174201
tools.append("clang-check")

clang/tools/clang-repl/ClangRepl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static llvm::Error sanitizeOopArguments(const char *ArgV0) {
124124
CLANG_VERSION_MAJOR_STRING);
125125
if (SystemTriple.isOSBinFormatELF())
126126
OrcRuntimePath =
127-
BasePath.str().str() + "lib/x86_64-unknown-linux-gnu/liborc_rt.a";
127+
BasePath.str().str() + "/lib/x86_64-unknown-linux-gnu/liborc_rt.a";
128128
else if (SystemTriple.isOSBinFormatMachO())
129129
OrcRuntimePath = BasePath.str().str() + "/lib/darwin/liborc_rt_osx.a";
130130
else

0 commit comments

Comments
 (0)