public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/21024] New: Type mismatch in a comparison.
@ 2005-04-14 16:19 kazu at cs dot umass dot edu
2005-04-14 16:48 ` [Bug c/21024] " pinskia at gcc dot gnu dot org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: kazu at cs dot umass dot edu @ 2005-04-14 16:19 UTC (permalink / raw)
To: gcc-bugs
Consider:
extern void *bar (void);
int
foo (unsigned int *p)
{
const void *r = bar ();
if (r >= (const void *) *p)
return 1;
return 0;
}
t03.generic looks like so.
foo (p)
{
void * D.1155;
unsigned int D.1156;
int D.1157;
const void * r;
D.1155 = bar ();
r = D.1155;
D.1156 = *p;
if (D.1156 <= r)
{
D.1157 = 1;
return D.1157;
}
else
{
}
D.1157 = 0;
return D.1157;
}
Note that "if (D.1156 <= r)" has a type mismatch, namely an integer type
v.s. a pointer type.
This PR is the real cause of PR 21021.
--
Summary: Type mismatch in a comparison.
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: kazu at cs dot umass dot edu
CC: dnovillo at redhat dot com,gcc-bugs at gcc dot gnu dot
org
OtherBugsDependingO 21021
nThis:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21024
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/21024] Type mismatch in a comparison.
2005-04-14 16:19 [Bug c/21024] New: Type mismatch in a comparison kazu at cs dot umass dot edu
@ 2005-04-14 16:48 ` pinskia at gcc dot gnu dot org
2005-04-15 16:38 ` [Bug c/21024] fold generates a comparison of two operands whose types do not match kazu at cs dot umass dot edu
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-14 16:48 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-04-14 16:48 -------
Confirmed. This has been wrong since "3.5.0 20040909".
--
What |Removed |Added
----------------------------------------------------------------------------
CC| |pinskia at gcc dot gnu dot
| |org
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Last reconfirmed|0000-00-00 00:00:00 |2005-04-14 16:48:13
date| |
Version|unknown |4.0.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21024
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/21024] fold generates a comparison of two operands whose types do not match
2005-04-14 16:19 [Bug c/21024] New: Type mismatch in a comparison kazu at cs dot umass dot edu
2005-04-14 16:48 ` [Bug c/21024] " pinskia at gcc dot gnu dot org
@ 2005-04-15 16:38 ` kazu at cs dot umass dot edu
2005-04-16 14:07 ` [Bug middle-end/21024] " kazu at cs dot umass dot edu
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: kazu at cs dot umass dot edu @ 2005-04-15 16:38 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From kazu at cs dot umass dot edu 2005-04-15 16:37 -------
build_binary_op builds a binary tree node for r >= (const void *) *q;
Here are the details.
(gdb) p resultcode
$2 = GE_EXPR
(gdb) call debug_tree(build_type)
<integer_type 0xb7cf5510 int public SI
size <integer_cst 0xb7ced408 type <integer_type 0xb7cf5288 bit_size_type>
constant invariant 32>
unit size <integer_cst 0xb7ced198 type <integer_type 0xb7cf521c unsigned
int> constant invariant 4>
align 32 symtab 0 alias set -1 precision 32 min <integer_cst 0xb7ced3c0
-2147483648> max <integer_cst 0xb7ced3d8 2147483647>
pointer_to_this <pointer_type 0xb7d029b4>>
(gdb) call debug_tree(op0)
<var_decl 0xb7d6a288 r
type <pointer_type 0xb7d6a21c
type <void_type 0xb7d6a1b0 void readonly VOID
align 8 symtab 0 alias set -1
pointer_to_this <pointer_type 0xb7d6a21c>>
unsigned SI
size <integer_cst 0xb7ced408 constant invariant 32>
unit size <integer_cst 0xb7ced198 constant invariant 4>
align 32 symtab 0 alias set -1>
used unsigned SI file test.c line 6 size <integer_cst 0xb7ced408 32> unit
size <integer_cst 0xb7ced198 4>
align 32 context <function_decl 0xb7d6a06c foo> initial <nop_expr 0xb7cf22c0>>
(gdb) call debug_tree(op1)
<convert_expr 0xb7cf2320
type <pointer_type 0xb7d6a21c
type <void_type 0xb7d6a1b0 void readonly VOID
align 8 symtab 0 alias set -1
pointer_to_this <pointer_type 0xb7d6a21c>>
unsigned SI
size <integer_cst 0xb7ced408 constant invariant 32>
unit size <integer_cst 0xb7ced198 constant invariant 4>
align 32 symtab 0 alias set -1>
arg 0 <indirect_ref 0xb7cf2300
type <integer_type 0xb7cf557c unsigned int public unsigned SI size
<integer_cst 0xb7ced408 32> unit size <integer_cst 0xb7ced198 4>
align 32 symtab 0 alias set -1 precision 32 min <integer_cst
0xb7ced480 0> max <integer_cst 0xb7ced468 4294967295>
pointer_to_this <pointer_type 0xb7d63e58>>
arg 0 <parm_decl 0xb7d63ec4 p type <pointer_type 0xb7d63e58>
used unsigned SI file test.c line 4 size <integer_cst 0xb7ced408 32>
unit size <integer_cst 0xb7ced198 4>
align 32 context <function_decl 0xb7d6a06c foo> result <pointer_type
0xb7d63e58> initial <pointer_type 0xb7d63e58> arg-type <pointer_type 0xb7d63e58>
arg-type-as-written <pointer_type 0xb7d63e58> chain <parm_decl 0xb7d63f30 q>>>>
Before the binary tree node is returned to the caller, build_binary_op
calls fold to fold the newly built tree node. Since the tree node is
a binary one, fold calls fold_binary. fold_binary strips what it
considers to be useless type conversion. By the time we get to the
case handling GE_EXPR, we have the following operands whose types do
not match.
(gdb) call debug_tree(arg0)
<var_decl 0xb7d6a288 r
type <pointer_type 0xb7d6a21c
type <void_type 0xb7d6a1b0 void readonly VOID
align 8 symtab 0 alias set -1
pointer_to_this <pointer_type 0xb7d6a21c>>
unsigned SI
size <integer_cst 0xb7ced408 constant invariant 32>
unit size <integer_cst 0xb7ced198 constant invariant 4>
align 32 symtab 0 alias set -1>
used unsigned SI file test.c line 6 size <integer_cst 0xb7ced408 32> unit
size <integer_cst 0xb7ced198 4>
align 32 context <function_decl 0xb7d6a06c foo> initial <nop_expr 0xb7cf22c0>>
(gdb) call debug_tree(arg1)
<indirect_ref 0xb7cf2300
type <integer_type 0xb7cf557c unsigned int public unsigned SI
size <integer_cst 0xb7ced408 constant invariant 32>
unit size <integer_cst 0xb7ced198 constant invariant 4>
align 32 symtab 0 alias set -1 precision 32 min <integer_cst 0xb7ced480
0> max <integer_cst 0xb7ced468 4294967295>
pointer_to_this <pointer_type 0xb7d63e58>>
arg 0 <parm_decl 0xb7d63ec4 p
type <pointer_type 0xb7d63e58 type <integer_type 0xb7cf557c unsigned int>
unsigned SI size <integer_cst 0xb7ced408 32> unit size <integer_cst
0xb7ced198 4>
align 32 symtab 0 alias set -1>
used unsigned SI file test.c line 4 size <integer_cst 0xb7ced408 32>
unit size <integer_cst 0xb7ced198 4>
align 32 context <function_decl 0xb7d6a06c foo> result <pointer_type
0xb7d63e58> initial <pointer_type 0xb7d63e58> arg-type <pointer_type 0xb7d63e58>
arg-type-as-written <pointer_type 0xb7d63e58>
chain <parm_decl 0xb7d63f30 q type <pointer_type 0xb7d63e58>
unsigned SI file test.c line 4 size <integer_cst 0xb7ced408 32> unit
size <integer_cst 0xb7ced198 4>
align 32 context <function_decl 0xb7d6a06c foo> result <pointer_type
0xb7d63e58> initial <pointer_type 0xb7d63e58> arg-type <pointer_type 0xb7d63e58>
arg-type-as-written <pointer_type 0xb7d63e58>>>>
Note that arg0 is of a pointer type, whereas arg1 is of an integer
type.
Roger, I don't think it's OK to create this kind of type mismatch.
At the very least, that would complicate SSA optimizers. Thoughts?
--
What |Removed |Added
----------------------------------------------------------------------------
CC| |roger at eyesopen dot com
Summary|Type mismatch in a |fold generates a comparison
|comparison. |of two operands whose types
| |do not match
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21024
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug middle-end/21024] fold generates a comparison of two operands whose types do not match
2005-04-14 16:19 [Bug c/21024] New: Type mismatch in a comparison kazu at cs dot umass dot edu
2005-04-14 16:48 ` [Bug c/21024] " pinskia at gcc dot gnu dot org
2005-04-15 16:38 ` [Bug c/21024] fold generates a comparison of two operands whose types do not match kazu at cs dot umass dot edu
@ 2005-04-16 14:07 ` kazu at cs dot umass dot edu
2005-04-17 1:38 ` cvs-commit at gcc dot gnu dot org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: kazu at cs dot umass dot edu @ 2005-04-16 14:07 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From kazu at cs dot umass dot edu 2005-04-16 14:07 -------
Patch posted:
http://gcc.gnu.org/ml/gcc-patches/2005-04/msg01830.html
--
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21024
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug middle-end/21024] fold generates a comparison of two operands whose types do not match
2005-04-14 16:19 [Bug c/21024] New: Type mismatch in a comparison kazu at cs dot umass dot edu
` (2 preceding siblings ...)
2005-04-16 14:07 ` [Bug middle-end/21024] " kazu at cs dot umass dot edu
@ 2005-04-17 1:38 ` cvs-commit at gcc dot gnu dot org
2005-04-17 1:41 ` kazu at cs dot umass dot edu
2005-04-20 2:06 ` pinskia at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-04-17 1:38 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From cvs-commit at gcc dot gnu dot org 2005-04-17 01:38 -------
Subject: Bug 21024
CVSROOT: /cvs/gcc
Module name: gcc
Changes by: kazu@gcc.gnu.org 2005-04-17 01:38:28
Modified files:
gcc : ChangeLog builtins.c fold-const.c
Log message:
PR middle-end/21024
* builtins.c (expand_builtin_strcat): Convert the result of
strlen to the right type.
* fold-const.c (fold_binary) <PLUS_EXPR>: Use fold_convert to
avoid creating type mismatches.
<GE_EXPR>: Pass op0 and op1 to fold_build2 to avoid creating
type mismatches.
Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.8326&r2=2.8327
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/builtins.c.diff?cvsroot=gcc&r1=1.455&r2=1.456
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fold-const.c.diff?cvsroot=gcc&r1=1.561&r2=1.562
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21024
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug middle-end/21024] fold generates a comparison of two operands whose types do not match
2005-04-14 16:19 [Bug c/21024] New: Type mismatch in a comparison kazu at cs dot umass dot edu
` (3 preceding siblings ...)
2005-04-17 1:38 ` cvs-commit at gcc dot gnu dot org
@ 2005-04-17 1:41 ` kazu at cs dot umass dot edu
2005-04-20 2:06 ` pinskia at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: kazu at cs dot umass dot edu @ 2005-04-17 1:41 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From kazu at cs dot umass dot edu 2005-04-17 01:41 -------
Just checked in a patch.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21024
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug middle-end/21024] fold generates a comparison of two operands whose types do not match
2005-04-14 16:19 [Bug c/21024] New: Type mismatch in a comparison kazu at cs dot umass dot edu
` (4 preceding siblings ...)
2005-04-17 1:41 ` kazu at cs dot umass dot edu
@ 2005-04-20 2:06 ` pinskia at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-20 2:06 UTC (permalink / raw)
To: gcc-bugs
--
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |4.1.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21024
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2005-04-20 2:06 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-14 16:19 [Bug c/21024] New: Type mismatch in a comparison kazu at cs dot umass dot edu
2005-04-14 16:48 ` [Bug c/21024] " pinskia at gcc dot gnu dot org
2005-04-15 16:38 ` [Bug c/21024] fold generates a comparison of two operands whose types do not match kazu at cs dot umass dot edu
2005-04-16 14:07 ` [Bug middle-end/21024] " kazu at cs dot umass dot edu
2005-04-17 1:38 ` cvs-commit at gcc dot gnu dot org
2005-04-17 1:41 ` kazu at cs dot umass dot edu
2005-04-20 2:06 ` pinskia at gcc dot gnu dot org
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).