NO

Author Topic: Error in the code generator for conditional allocation  (Read 10498 times)

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Error in the code generator for conditional allocation
« on: November 06, 2008, 09:33:47 PM »
Hi Pelle

I think, I have found an error in the code generator for condition allocation. I tried to port WinVI (http://www.winvi.de/en/) to Pelles C. In the file "Paint.c" in the function "TextLine" in the source line 1187 there is a conditional allocation. In the false path of this allocation the compiler forgets to calculate the address where to write the data.

I have tried to reduce to code which produces this fault, but unfortunately I was not successful. So I try to add the complete project. So that you can search for the misstake.

best regards
Alex  ;)
« Last Edit: November 07, 2008, 08:43:02 AM by AlexN »
best regards
 Alex ;)

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Error in the code generator for conditional allocation
« Reply #1 on: November 06, 2008, 09:34:52 PM »
« Last Edit: November 07, 2008, 08:43:21 AM by AlexN »
best regards
 Alex ;)

severach

  • Guest
Re: Error in the code generator for conditional allocation
« Reply #2 on: November 09, 2008, 07:45:00 AM »
Pelles has a project manager bug where it puts the real name of the include folder in WinVI.ppj for the .rc file. It should be using $(PellesCDir)\Include\Win. I worked around this by removing and adding the .rc file.

Quote
PORC: ...\WINVI\Winvi.rc(16): fatal error: Can't find include file WinVi32.rc.

Code: (paint.c) [Select]
p = Line ? LineInfo[Line].Pos : ScreenStart;Line 1187 is not an allocation but a structure copy. Because POSITION is 3 elements Pelles chooses to do it by copying each of the 3 elements rather than a generic memcpy(). I can't get the compile to complete so I made a conditional structure copy with the POSITION structure and another larger structure with enough elements that Pelles chooses a memcpy() variant. Both assembly listings look like they should work. I didn't test because I do not allow implicit structure copies anywhere in my code.

Avoid this project as a code learning exercise.

How To Write Unmaintainable Code

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Error in the code generator for conditional allocation
« Reply #3 on: November 09, 2008, 07:48:29 PM »

Quote
PORC: ...\WINVI\Winvi.rc(16): fatal error: Can't find include file WinVi32.rc.

You can find the complete (I hope so) project at http://members.vienna.at/neumeister/software/WinVI.zip or http://members.aon.at/aneumeister/Programme/WinVI.zip.

Quote
Code: (paint.c) [Select]
p = Line ? LineInfo[Line].Pos : ScreenStart;Line 1187 is not an allocation but a structure copy. Because POSITION is 3 elements Pelles chooses to do it by copying each of the 3 elements rather than a generic memcpy(). I can't get the compile to complete so I made a conditional structure copy with the POSITION structure and another larger structure with enough elements that Pelles chooses a memcpy() variant. Both assembly listings look like they should work. I didn't test because I do not allow implicit structure copies anywhere in my code.

Avoid this project as a code learning exercise.

How To Write Unmaintainable Code


The main probleme is (if you use any optimizer) that in the "false" path the destination address is never read, so it is impossible to write to the variable (structure) p.

To avoid the probleme, there is the easiest way to deactivate optmization for this code-line, or you can eliminate the static from the declaration of p ...

I have tried to reproduce this fault in a short program and there I was not sucessful. To find a workaround, was not very hard after knew what the problem is.

I hope Pelle can find what the problem is and can fix it (when not I have also no problem ;) )
« Last Edit: November 09, 2008, 08:58:57 PM by AlexN »
best regards
 Alex ;)

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Error in the code generator for conditional allocation
« Reply #4 on: May 08, 2009, 08:53:10 AM »
This is not a good program for Pelles C, version 5 crashes - version 6 don't crash but calculates the window size wrong. If I have enough time, I will look why.
Are the variables are initialized in an other way now?
best regards
 Alex ;)

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: Error in the code generator for conditional allocation
« Reply #5 on: May 10, 2009, 01:00:27 PM »
The SSA form/optimizations can change things, so maybe. Initializing with a constant (integer, null pointer, ...) can move the initialization closer to the point where it's first needed.

Does it work without optimizations turned on?

I will look at it, but right now it's not obvious to me where the problem is (and where I should start looking)...
/Pelle

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: Error in the code generator for conditional allocation
« Reply #6 on: May 10, 2009, 01:54:34 PM »
WinVi32.rc seems to be missing...
/Pelle

JohnF

  • Guest
Re: Error in the code generator for conditional allocation
« Reply #7 on: May 10, 2009, 03:15:39 PM »
In the second message Alex posted the rc file.

John

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: Error in the code generator for conditional allocation
« Reply #8 on: May 12, 2009, 05:37:33 PM »
I can only find winvi.rc there - WinVi32.rc is included from winvi.rc...

Anyway, unless I have the exact same source code, and a pointer to where the compiler is assumed to do something wrong, I can't do much. Guessing which package to download from where isn't going to help me. Is the OP still using the code posted here, or some other modified version...?
/Pelle

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Error in the code generator for conditional allocation
« Reply #9 on: May 12, 2009, 08:34:53 PM »
I can only find winvi.rc there - WinVi32.rc is included from winvi.rc...

Sorry!
I hope, I have added now all you need to build it.

best regards
 Alex ;)

JohnF

  • Guest
Re: Error in the code generator for conditional allocation
« Reply #10 on: May 13, 2009, 10:52:54 AM »
I eventually got it to compile - if anyone wants to have it, it's on my web site as it's too large to post here complete.

http://www.johnfindlay.plus.com/pellesc/WinVI.zip

John
« Last Edit: May 13, 2009, 10:58:03 AM by JohnF »

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: Error in the code generator for conditional allocation
« Reply #11 on: May 13, 2009, 01:53:19 PM »
OK, I can finally build and run the program. I can't see any problem in v6.0 for the originally reported problem. I can see some painting problems, but are we sure this code actually works?! Until I see some proof there is a compiler bug, I will assume the compiler is working correctly.
/Pelle

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Error in the code generator for conditional allocation
« Reply #12 on: May 13, 2009, 02:39:04 PM »
OK, I can finally build and run the program. I can't see any problem in v6.0 for the originally reported problem. I can see some painting problems, but are we sure this code actually works?! Until I see some proof there is a compiler bug, I will assume the compiler is working correctly.

OK, I think that I found the problem.  :)

In the file WinVI.c in line 1149 there is a local variable SaveClientRect (RECT SaveClientRect) defined which gets the same adress like the local variable Rect (RECT Rect) defined in line 1143. Two variables at the same memory is not so good.  :(

If I force to get another adress for SaveClientRect with the instruction static, all works fine.  :)

PS: For the compiler v6.0 the topic is not correct. I would say, there is a problem with local variables.
« Last Edit: May 14, 2009, 10:08:39 AM by AlexN »
best regards
 Alex ;)

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Error in the code generator for conditional allocation
« Reply #13 on: May 13, 2009, 02:57:57 PM »
I eventually got it to compile - if anyone wants to have it, it's on my web site as it's too large to post here complete.

http://www.johnfindlay.plus.com/pellesc/WinVI.zip

John


The original website for this program (without adaptation for Pelles C) you can find at:

http://www.winvi.de/
best regards
 Alex ;)

JohnF

  • Guest
Re: Error in the code generator for conditional allocation
« Reply #14 on: May 15, 2009, 08:42:32 AM »
OK, I can finally build and run the program. I can't see any problem in v6.0 for the originally reported problem. I can see some painting problems, but are we sure this code actually works?! Until I see some proof there is a compiler bug, I will assume the compiler is working correctly.

I can confirm the code works if one makes one of the RECT structs static - here

case WM_ERASEBKGND:
    if (hwndMain)
    {
        static RECT Rect;

John