aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-11-18 00:10:23 +0100
committerEugen Wissner <belka@caraus.de>2026-11-20 00:08:40 +0100
commitd4681529c20d5cb2630bfe09f4cf4c4ca4c98a23 (patch)
treed11bc100c2e35fe7ee8e84837d8e2826e4b8731e /gcc
parent9b4b13e0d9030bb21c86eea6c4ba00bf4d91f0a0 (diff)
downloadelna-cpp.tar.gz
Restrict pointer subtraction by typeHEADcpp
Diffstat (limited to 'gcc')
-rw-r--r--gcc/gcc/elna-tree.cc9
1 files changed, 6 insertions, 3 deletions
diff --git a/gcc/gcc/elna-tree.cc b/gcc/gcc/elna-tree.cc
index 9612ae2..afc809b 100644
--- a/gcc/gcc/elna-tree.cc
+++ b/gcc/gcc/elna-tree.cc
@@ -138,11 +138,14 @@ namespace elna::gcc
convert_expression = fold_build1(NEGATE_EXPR, size_type_node, convert_expression);
return fold_build2_loc(operation_location, POINTER_PLUS_EXPR, pointer_type, left, convert_expression);
}
- else if (POINTER_TYPE_P(left_type) && POINTER_TYPE_P(right_type) && left_type == right_type)
+ else if (POINTER_TYPE_P(left_type) && POINTER_TYPE_P(right_type))
{
- return fold_build2_loc(operation_location, POINTER_DIFF_EXPR, ptrdiff_type_node, left, right);
+ tree size_exp = pointer_stride(left_type, ptrdiff_type_node);
+ tree diff = fold_build2_loc(operation_location, POINTER_DIFF_EXPR, ptrdiff_type_node, left, right);
+
+ return fold_build2_loc(operation_location, EXACT_DIV_EXPR, ptrdiff_type_node, diff, size_exp);
}
- return error_mark_node;
+ gcc_unreachable();
}
gcc_unreachable();
}