[Bug d/96429] d: Pointer subtraction uses TRUNC_DIV_EXPR
ibuclaw at gdcproject dot org
gcc-bugzilla@gcc.gnu.org
Mon Aug 3 12:21:12 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96429
--- Comment #1 from Iain Buclaw <ibuclaw at gdcproject dot org> ---
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -620,6 +620,18 @@ public:
break;
case TOKdiv:
+ /* Determine if the div expression is a lowered pointer diff operation.
+ The front-end rewrites `(p1 - p2)' into `(p1 - p2) / stride'. */
+ if (MinExp *me = e->e1->isMinExp ())
+ {
+ if (me->e1->type->ty == Tpointer && me->e2->type->ty == Tpointer
+ && e->e2->op == TOKint64)
+ {
+ code = EXACT_DIV_EXPR;
+ break;
+ }
+ }
+
code = e->e1->type->isintegral ()
? TRUNC_DIV_EXPR : RDIV_EXPR;
break;
More information about the Gcc-bugs
mailing list