Debian Codegraph @

clang/test/Interpreter/out-of-process.cpp

raw
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