public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/42129] New: ICE in pointer difference with sizeof(int)>sizeof(void *)
@ 2009-11-21 6:39 kikairoya at gmail dot com
0 siblings, 0 replies; only message in thread
From: kikairoya at gmail dot com @ 2009-11-21 6:39 UTC (permalink / raw)
To: gcc-bugs
ICE in pointer difference operation in C++ (without C).
This causes only sizeof(int)>sizeof(void *) platform such as h8300-elf with -mh
-mn -mint32.
test case:
==================================
typedef int *T;
T p, q;
int main() {
int v = p - q;
}
==================================
Dump gimplified this,
p - q
converted to
((int)(short int)p - (int)(short int)q) / sizeof(T) [with result_type = short
int]
This problem caused because of generated "/ sizeof(T)" as ptrdiff_t(= short
int) but should be int.
Most of platforms are sizeof(ptrdiff_t)>sizeof(int), this problem is not
appeared.
In specially case, T = char, "/ sizeof(T)" is folded and problem does not
appear.
To fix this, generate "/ sizeof(T)" and return type as same type of
"((int)(short int)p - (int)(short int)q)".
Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c (revision 154402)
+++ gcc/cp/typeck.c (working copy)
@@ -4209,6 +4209,7 @@
tree result;
tree restype = ptrdiff_type_node;
tree target_type = TREE_TYPE (ptrtype);
+ tree internal_type;
if (!complete_type_or_else (target_type, NULL_TREE))
return error_mark_node;
@@ -4229,6 +4230,8 @@
cp_convert (restype, op1),
tf_warning_or_error);
+ internal_type = TREE_TYPE (op0);
+
/* This generates an error if op1 is a pointer to an incomplete type. */
if (!COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (op1))))
error ("invalid use of a pointer to an incomplete type in pointer
arithmetic");
@@ -4239,8 +4242,8 @@
/* Do the division. */
- result = build2 (EXACT_DIV_EXPR, restype, op0, cp_convert (restype, op1));
- return fold_if_not_in_template (result);
+ result = build2 (EXACT_DIV_EXPR, internal_type, op0, cp_convert
(internal_type, op1));
+ return fold_if_not_in_template (cp_convert (restype, result));
}
/* Construct and perhaps optimize a tree representation
--
Summary: ICE in pointer difference with sizeof(int)>sizeof(void
*)
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: kikairoya at gmail dot com
GCC target triplet: h8300-elf
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42129
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-11-21 6:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-21 6:39 [Bug c++/42129] New: ICE in pointer difference with sizeof(int)>sizeof(void *) kikairoya at gmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).