aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend_stmt.cpp
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2022-03-21 11:16:59 +0000
committerGitHub <noreply@github.com>2022-03-21 11:16:59 +0000
commit559fcfa2917d448b94899fc0ff3a921e8d6c4e0d (patch)
tree3a61e248ffb93418477ee92e7ed1847137e26c78 /src/llvm_backend_stmt.cpp
parent84cee5d9d5af876da6ac07738d1cd607bdc4aabd (diff)
parentfdbbf242718746ad71cb410162c6d0b8c68c5af0 (diff)
Merge pull request #1632 from gitlost/const_in_if_#1592
Fix issue #1592 "LLVM code gen error when using a constant in an if"
Diffstat (limited to 'src/llvm_backend_stmt.cpp')
-rw-r--r--src/llvm_backend_stmt.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/llvm_backend_stmt.cpp b/src/llvm_backend_stmt.cpp
index 916c0433e..2afb5300b 100644
--- a/src/llvm_backend_stmt.cpp
+++ b/src/llvm_backend_stmt.cpp
@@ -1652,13 +1652,16 @@ void lb_build_if_stmt(lbProcedure *p, Ast *node) {
}
lbValue cond = lb_build_cond(p, is->cond, then, else_);
+ // Note `cond.value` only set for non-and/or conditions and const negs so that the `LLVMIsConstant()`
+ // and `LLVMConstIntGetZExtValue()` calls below will be valid and `LLVMInstructionEraseFromParent()`
+ // will target the correct (& only) branch statement
if (is->label != nullptr) {
lbTargetList *tl = lb_push_target_list(p, is->label, done, nullptr, nullptr);
tl->is_block = true;
}
- if (LLVMIsConstant(cond.value)) {
+ if (cond.value && LLVMIsConstant(cond.value)) {
// NOTE(bill): Do a compile time short circuit for when the condition is constantly known.
// This done manually rather than relying on the SSA passes because sometimes the SSA passes
// miss some even if they are constantly known, especially with few optimization passes.