Skip to content

Commit a18690b

Browse files
authored
Merge pull request #2070 from Shaikh-Ubaid/ifexp_llvm
LLVM: Fix visit_IfExp()
2 parents dde47f4 + 2a4c3e0 commit a18690b

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

integration_tests/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,8 @@ RUN(NAME test_global LABELS cpython llvm c)
554554
RUN(NAME test_global_decl LABELS cpython llvm c)
555555
RUN(NAME test_integer_bitnot LABELS cpython llvm c wasm)
556556
RUN(NAME test_unsign_int_bitnot LABELS cpython llvm c)
557-
RUN(NAME test_ifexp LABELS cpython llvm c)
557+
RUN(NAME test_ifexp_01 LABELS cpython llvm c)
558+
RUN(NAME test_ifexp_02 LABELS cpython llvm c)
558559
RUN(NAME test_unary_minus LABELS cpython llvm c)
559560
RUN(NAME test_unary_plus LABELS cpython llvm c)
560561
RUN(NAME test_bool_binop LABELS cpython llvm c)
File renamed without changes.

integration_tests/test_ifexp_02.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from lpython import i32
2+
3+
def g() -> i32:
4+
return 10
5+
6+
def f():
7+
i: i32
8+
j: i32
9+
k: i32
10+
i = 5
11+
j = 6
12+
k = g() if i > j else g() - 1
13+
14+
print(k)
15+
assert k == 9
16+
17+
f()

src/libasr/codegen/asr_to_llvm.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5667,15 +5667,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
56675667
// IfExp(expr test, expr body, expr orelse, ttype type, expr? value)
56685668
this->visit_expr_wrapper(x.m_test, true);
56695669
llvm::Value *cond = tmp;
5670-
llvm::Value *then_val = nullptr;
5671-
llvm::Value *else_val = nullptr;
5672-
llvm_utils->create_if_else(cond, [=, &then_val]() {
5673-
this->visit_expr_wrapper(x.m_body, true);
5674-
then_val = tmp;
5675-
}, [=, &else_val]() {
5676-
this->visit_expr_wrapper(x.m_orelse, true);
5677-
else_val = tmp;
5678-
});
5670+
this->visit_expr_wrapper(x.m_body, true);
5671+
llvm::Value *then_val = tmp;
5672+
this->visit_expr_wrapper(x.m_orelse, true);
5673+
llvm::Value *else_val = tmp;
56795674
tmp = builder->CreateSelect(cond, then_val, else_val);
56805675
}
56815676

0 commit comments

Comments
 (0)