[pkg-d-commits] [ldc] 51/211: Produce correct code for increment/decrement operations on complex types (#1809)
Matthias Klumpp
mak at moszumanska.debian.org
Sun Apr 23 22:36:09 UTC 2017
This is an automated email from the git hooks/post-receive script.
mak pushed a commit to annotated tag v1.1.0
in repository ldc.
commit 6054564735de3933cfb58aea771823e85da66917
Author: LemonBoy <LemonBoy at users.noreply.github.com>
Date: Wed Oct 5 23:17:32 2016 +0200
Produce correct code for increment/decrement operations on complex types (#1809)
Fixes issue #1806.
---
gen/toir.cpp | 20 ++++++++++++++++++--
tests/codegen/complex_postexpr_gh1806.d | 22 ++++++++++++++++++++++
2 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/gen/toir.cpp b/gen/toir.cpp
index b75304e..8f5ef6d 100644
--- a/gen/toir.cpp
+++ b/gen/toir.cpp
@@ -1364,7 +1364,8 @@ public:
auto &PGO = gIR->funcGen().pgo;
PGO.setCurrentStmt(e);
- LLValue *const lval = DtoLVal(e->e1);
+ DValue *const dv = toElem(e->e1);
+ LLValue *const lval = DtoLVal(dv);
toElem(e->e2);
LLValue *val = DtoLoad(lval);
@@ -1387,6 +1388,17 @@ public:
LLConstant *offset =
e->op == TOKplusplus ? DtoConstUint(1) : DtoConstInt(-1);
post = DtoGEP1(val, offset, false, "", p->scopebb());
+ } else if (e1type->iscomplex()) {
+ assert(e2type->iscomplex());
+ LLValue *one = LLConstantFP::get(DtoComplexBaseType(e1type), 1.0);
+ LLValue *re, *im;
+ DtoGetComplexParts(e->loc, e1type, dv, re, im);
+ if (e->op == TOKplusplus) {
+ re = llvm::BinaryOperator::CreateFAdd(re, one, "", p->scopebb());
+ } else if (e->op == TOKminusminus) {
+ re = llvm::BinaryOperator::CreateFSub(re, one, "", p->scopebb());
+ }
+ DtoComplexSet(lval, re, im);
} else if (e1type->isfloating()) {
assert(e2type->isfloating());
LLValue *one = DtoConstFP(e1type, ldouble(1.0));
@@ -1399,7 +1411,11 @@ public:
llvm_unreachable("Unsupported type for PostExp.");
}
- DtoStore(post, lval);
+ // The real part of the complex number has already been updated, skip the
+ // store
+ if (!e1type->iscomplex()) {
+ DtoStore(post, lval);
+ }
result = new DImValue(e->type, val);
}
diff --git a/tests/codegen/complex_postexpr_gh1806.d b/tests/codegen/complex_postexpr_gh1806.d
new file mode 100644
index 0000000..bdc35c9
--- /dev/null
+++ b/tests/codegen/complex_postexpr_gh1806.d
@@ -0,0 +1,22 @@
+// RUN: %ldc -run %s
+
+void runTest(T)() {
+ {
+ T v = 1.0 + 1.0i;
+ assert(v++ == 1.0 + 1.0i);
+ assert(v-- == 2.0 + 1.0i);
+ assert(v == 1.0 + 1.0i);
+ }
+ {
+ T v = 1.0 + 1.0i;
+ assert(++v == 2.0 + 1.0i);
+ assert(--v == 1.0 + 1.0i);
+ assert(v == 1.0 + 1.0i);
+ }
+}
+
+void main () {
+ runTest!cfloat();
+ runTest!cdouble();
+ runTest!creal();
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git
More information about the pkg-d-commits
mailing list