public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/44681]  New: usage of macro in loop boundary leads to crash
@ 2010-06-26 13:26 jd at cococo dot de
  2010-06-27 23:21 ` [Bug middle-end/44681] " pinskia at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: jd at cococo dot de @ 2010-06-26 13:26 UTC (permalink / raw)
  To: gcc-bugs

When porting my software from Win32 to Linux, i had to recompile it with gcc
under Mingw and also under Linux. There was a hurdle, because the loop shown
below in b) crashed after a while on both platforms. (I was happy to find the
location of the bug with gdb!) After rearranging the code like c) it worked
properly.
Sorry, but i am not able to provide test data. Maybe someone will see at once,
where the problem is located.

Greetings
Jens
http://cococo.de

a) prerequisite
#define max(a,b)            a>b?a:b

b) buggy variant (for loop in line 13)
//------------------------------------------------------------------------------
//copy column left to right
//------------------------------------------------------------------------------
void copyvector(Tree pre,Tree left,int lc,Tree right,int rc) {
  int nr;
  callsofcopyvector++;
  //check initialization of precondition
  defval(left,right,rc,coeff(left,0,lc));
  right->functype=left->functype;
  right->bordertype=left->bordertype;
  right->symtype=left->symtype;
  right->reversive=left->reversive;
  for (nr=0;nr <= max(left->rows,right->rows);nr++) {//now do composition of
functions
         if (nr <= right->rows)
                asg(right,nr,rc,0);
         if ((nr <= left->rows) && (nr <= right->rows)) {
                Tree ur=coeff(left,nr,lc);
                //debug(coeff(left,nr,0))
                asg(right,nr,rc,ur);
         }
  }
  asg(right,0,rc,pre);
  checkunreachable(right,right,rc);
  return;
}
c) working variant
//------------------------------------------------------------------------------
//copy column left to right
//------------------------------------------------------------------------------
void copyvector(Tree pre,Tree left,int lc,Tree right,int rc) {
  int nr,mav=max(left->rows,right->rows);
  callsofcopyvector++;
  //check initialization of precondition
  defval(left,right,rc,coeff(left,0,lc));
  right->functype=left->functype;
  right->bordertype=left->bordertype;
  right->symtype=left->symtype;
  right->reversive=left->reversive;
  for (nr=0;nr <= mav;nr++) {//now do composition of functions
         if (nr <= right->rows)
                asg(right,nr,rc,0);
         if ((nr <= left->rows) && (nr <= right->rows)) {
                Tree ur=coeff(left,nr,lc);
                //debug(coeff(left,nr,0))
                asg(right,nr,rc,ur);
         }
  }
  asg(right,0,rc,pre);
  checkunreachable(right,right,rc);
  return;
}


-- 
           Summary: usage of macro in loop boundary leads to crash
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: blocker
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jd at cococo dot de


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44681


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug middle-end/44681] usage of macro in loop boundary leads to crash
  2010-06-26 13:26 [Bug c/44681] New: usage of macro in loop boundary leads to crash jd at cococo dot de
@ 2010-06-27 23:21 ` pinskia at gcc dot gnu dot org
  2010-06-27 23:23 ` pinskia at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-06-27 23:21 UTC (permalink / raw)
  To: gcc-bugs



-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|blocker                     |normal
          Component|c                           |middle-end


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44681


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug middle-end/44681] usage of macro in loop boundary leads to crash
  2010-06-26 13:26 [Bug c/44681] New: usage of macro in loop boundary leads to crash jd at cococo dot de
  2010-06-27 23:21 ` [Bug middle-end/44681] " pinskia at gcc dot gnu dot org
@ 2010-06-27 23:23 ` pinskia at gcc dot gnu dot org
  2010-06-27 23:31 ` redi at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-06-27 23:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2010-06-27 23:23 -------
Can you provide the preprocessed source?  The code snip does not compile
without the definitions of Tree.  Oh Can asg/coeff change its arguments.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44681


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug middle-end/44681] usage of macro in loop boundary leads to crash
  2010-06-26 13:26 [Bug c/44681] New: usage of macro in loop boundary leads to crash jd at cococo dot de
  2010-06-27 23:21 ` [Bug middle-end/44681] " pinskia at gcc dot gnu dot org
  2010-06-27 23:23 ` pinskia at gcc dot gnu dot org
@ 2010-06-27 23:31 ` redi at gcc dot gnu dot org
  2010-06-30 10:32 ` jd at cococo dot de
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-06-27 23:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from redi at gcc dot gnu dot org  2010-06-27 23:31 -------
is this just an operator precedence misunderstanding?

the loop condition expands to 
nr <= left->rows > right->rows ? left->rows : right->rows

try adding parentheses to the macro definition


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44681


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug middle-end/44681] usage of macro in loop boundary leads to crash
  2010-06-26 13:26 [Bug c/44681] New: usage of macro in loop boundary leads to crash jd at cococo dot de
                   ` (2 preceding siblings ...)
  2010-06-27 23:31 ` redi at gcc dot gnu dot org
@ 2010-06-30 10:32 ` jd at cococo dot de
  2010-06-30 10:57 ` redi at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jd at cococo dot de @ 2010-06-30 10:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jd at cococo dot de  2010-06-30 10:32 -------
You are right - it was a matter of bracketing. After having changed the macro
to
  #define max(a,b)            (a>b?a:b)
it works fine on MingW and Linux.

The problem lies in an incompatibility between to Delphi 2010. Delphi processed
it according to my intention and gcc interprets it differently.

Thanks,
Jens 


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44681


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug middle-end/44681] usage of macro in loop boundary leads to crash
  2010-06-26 13:26 [Bug c/44681] New: usage of macro in loop boundary leads to crash jd at cococo dot de
                   ` (3 preceding siblings ...)
  2010-06-30 10:32 ` jd at cococo dot de
@ 2010-06-30 10:57 ` redi at gcc dot gnu dot org
  2010-06-30 13:44 ` jd at cococo dot de
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-06-30 10:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from redi at gcc dot gnu dot org  2010-06-30 10:57 -------
Delphi and C have different operator precedence


-- 

redi at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44681


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug middle-end/44681] usage of macro in loop boundary leads to crash
  2010-06-26 13:26 [Bug c/44681] New: usage of macro in loop boundary leads to crash jd at cococo dot de
                   ` (4 preceding siblings ...)
  2010-06-30 10:57 ` redi at gcc dot gnu dot org
@ 2010-06-30 13:44 ` jd at cococo dot de
  2010-06-30 14:16 ` redi at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jd at cococo dot de @ 2010-06-30 13:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jd at cococo dot de  2010-06-30 13:43 -------
Which is the standard C operator precedence? It should not depend on the
dialect. Is there a pragma for it?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44681


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug middle-end/44681] usage of macro in loop boundary leads to crash
  2010-06-26 13:26 [Bug c/44681] New: usage of macro in loop boundary leads to crash jd at cococo dot de
                   ` (5 preceding siblings ...)
  2010-06-30 13:44 ` jd at cococo dot de
@ 2010-06-30 14:16 ` redi at gcc dot gnu dot org
  2010-06-30 16:47 ` jd at cococo dot de
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-06-30 14:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from redi at gcc dot gnu dot org  2010-06-30 14:15 -------
(In reply to comment #5)
> Which is the standard C operator precedence?

You can find that for yourself on the web e.g.
http://en.wikipedia.org/wiki/Operator_precedence_in_C

GCC uses the standard precedence.

> It should not depend on the dialect. 

I don't know what you mean. Delphi is based on Pascal, isn't it?
Pascal and C are different languages.

> Is there a pragma for it?

Not in GCC.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44681


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug middle-end/44681] usage of macro in loop boundary leads to crash
  2010-06-26 13:26 [Bug c/44681] New: usage of macro in loop boundary leads to crash jd at cococo dot de
                   ` (6 preceding siblings ...)
  2010-06-30 14:16 ` redi at gcc dot gnu dot org
@ 2010-06-30 16:47 ` jd at cococo dot de
  2010-06-30 17:10 ` redi at gcc dot gnu dot org
  2010-07-01  5:37 ` jd at cococo dot de
  9 siblings, 0 replies; 11+ messages in thread
From: jd at cococo dot de @ 2010-06-30 16:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from jd at cococo dot de  2010-06-30 16:47 -------
Sorry, I was not precise enough. Delphi is the IDE for both, Pascal and C, and
what I meant by the word are the language(s) Borland C and C++. They have an
option for Standard C. Maybe I misunderstood it ... 


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44681


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug middle-end/44681] usage of macro in loop boundary leads to crash
  2010-06-26 13:26 [Bug c/44681] New: usage of macro in loop boundary leads to crash jd at cococo dot de
                   ` (7 preceding siblings ...)
  2010-06-30 16:47 ` jd at cococo dot de
@ 2010-06-30 17:10 ` redi at gcc dot gnu dot org
  2010-07-01  5:37 ` jd at cococo dot de
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-06-30 17:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from redi at gcc dot gnu dot org  2010-06-30 17:10 -------
(In reply to comment #7)
> Sorry, I was not precise enough. Delphi is the IDE for both, Pascal and C, and
> what I meant by the word are the language(s) Borland C and C++. They have an
> option for Standard C. Maybe I misunderstood it ... 

Well if they disagree then Borland is wrong :-)

The precedence rules of C mean that this

  nr <= left->rows > right->rows ? left->rows : right->rows

is interpreted as 

  ((nr <= left->rows) > right->rows) ? left->rows : right->rows

so your loop condition is either 'left->rows' or 'right->rows'

so if both those values are non-zero then you loop will never exit, regardless
of the value of 'nr'


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44681


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug middle-end/44681] usage of macro in loop boundary leads to crash
  2010-06-26 13:26 [Bug c/44681] New: usage of macro in loop boundary leads to crash jd at cococo dot de
                   ` (8 preceding siblings ...)
  2010-06-30 17:10 ` redi at gcc dot gnu dot org
@ 2010-07-01  5:37 ` jd at cococo dot de
  9 siblings, 0 replies; 11+ messages in thread
From: jd at cococo dot de @ 2010-07-01  5:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from jd at cococo dot de  2010-07-01 05:37 -------
Ok, but in terms of semantics there is only one way of interpreting the
sentence

  nr <= left->rows > right->rows ? left->rows : right->rows

because we have to differ between conditions yielding truth values and
expressions yielding numbers. So from a domain theoretic point of view I
assumed it to be

  nr <= ((left->rows > right->rows) ? left->rows : right->rows)

Have a nice day,
Jens


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44681


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2010-07-01  5:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-26 13:26 [Bug c/44681] New: usage of macro in loop boundary leads to crash jd at cococo dot de
2010-06-27 23:21 ` [Bug middle-end/44681] " pinskia at gcc dot gnu dot org
2010-06-27 23:23 ` pinskia at gcc dot gnu dot org
2010-06-27 23:31 ` redi at gcc dot gnu dot org
2010-06-30 10:32 ` jd at cococo dot de
2010-06-30 10:57 ` redi at gcc dot gnu dot org
2010-06-30 13:44 ` jd at cococo dot de
2010-06-30 14:16 ` redi at gcc dot gnu dot org
2010-06-30 16:47 ` jd at cococo dot de
2010-06-30 17:10 ` redi at gcc dot gnu dot org
2010-07-01  5:37 ` jd at cococo dot de

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).