473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Compiler generated code bug in Debug build

Hi,

I have found a bug in generated code in debug build. I have Visual C++ .NET
7.1.3088. Function Buggy::isBug() returns true and it should return false.
The sample is contrived to exhibit the bug in small code. The expression

m_array + sizeof(Buggy) * m_used

is actualy compiled as

m_array + sizeof(Buggy) * sizeof(Buggy) * m_used

If you look into assembly you should see something like this:

00411276 mov eax,dword ptr [this]
00411279 mov ecx,dword ptr [eax+1F8h]
0041127F imul ecx,ecx,1FCh
00411285 imul ecx,ecx,1FCh // <<<<<<<< ????
0041128B mov edx,dword ptr [this]
0041128E add ecx,dword ptr [edx+1F4h]
Thanks for any feedback, Jan
The sample code
===============
struct Buggy
{
char ch[500];// must be bigger otherwise shl will be used instead of imul
Buggy* m_array;
int m_used;

bool isBug()
{
m_array = 0;
m_used = 1;

return sizeof(Buggy) != int(m_array + sizeof(Buggy) * m_used);
}
};

int main()
{
Buggy test;

test.isBug();

return 0;
}
Nov 17 '05 #1
2 1320
Jan Bares wrote:
Hi,

I have found a bug in generated code in debug build. I have Visual
C++ .NET
Actually, you haven't. See below for the source of your misunderstanding.
7.1.3088. Function Buggy::isBug() returns true and it should return
false. The sample is contrived to exhibit the bug in small code. The
expression

m_array + sizeof(Buggy) * m_used

is actualy compiled as

m_array + sizeof(Buggy) * sizeof(Buggy) * m_used
Actually, it's not.

If you look into assembly you should see something like this:

00411276 mov eax,dword ptr [this]
00411279 mov ecx,dword ptr [eax+1F8h]
0041127F imul ecx,ecx,1FCh
00411285 imul ecx,ecx,1FCh // <<<<<<<< ????
0041128B mov edx,dword ptr [this]
0041128E add ecx,dword ptr [edx+1F4h]
Thanks for any feedback, Jan
The sample code
===============
struct Buggy
{
char ch[500];
Buggy* m_array;
int m_used;

bool isBug()
{
m_array = 0;
m_used = 1;

return sizeof(Buggy) != int(m_array + sizeof(Buggy) * m_used);
The compiler is doing exactly what you told it. m_array is of type Buggy*.
m_array+sizeof(Buggy) is also of type Buggy* - its value is computed by
multiplying (*m_array) by sizeof(Buggy) and then adding the result to
m_array. Remember, you're doing pointer math here. The compiler correctly
observed that m_used==1 and didn't emit any code to perform that
calculation.

Presumably you meant to write:

return sizeof(Buggy) != int(m_array) + sizeof(Buggy) * m_used;

.... or something like that. It's not clear what this code is supposed to
do, but then you did say it's contrived.
}
};

int main()
{
Buggy test;

test.isBug();

return 0;
}


If you still have problems with some uncontrived code, please post again.

-cd
Nov 17 '05 #2
Thanks Carl, I just realized that and wanted to disregard this stupidity, I
must be off my brain.

Jan
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Martin | last post by:
The original question is at the bottom: > What OS are you using? Windows 2000 Server SP3 with VS.NET 2003 > How much memory do you have? 512MB, of which typically at least half is...
6
by: paul calvert | last post by:
I hope somewhere here has encountered and solved a similar problem in the past. 1) on a new Win2000 PC: installed Visual C++ 6.0 download & install single file Service Pack 5.0 2) try to...
3
by: Mark Rockman | last post by:
------ Build started: Project: USDAver2, Configuration: Debug .NET ------ Preparing resources... Updating references... Performing main compilation... error CS0583: Internal Compiler Error...
9
by: JTrigger | last post by:
When I compile my project using the IDE on a development machine it works just fine. When I compile it on the server using csc.exe, I get the following error when I try to bring it up in the web...
1
by: Razzie | last post by:
Hi all, I was working on a little project, worked fine, but now all of a sudden I get: The compiler failed with error code -1073741502 as an error message (when running the site, not...
44
by: Don Kim | last post by:
Ok, so I posted a rant earlier about the lack of marketing for C++/CLI, and it forked over into another rant about which was the faster compiler. Some said C# was just as fast as C++/CLI, whereas...
41
by: Miroslaw Makowiecki | last post by:
Where can I download Comeau compiler as a trial version? Thanks in advice.
42
by: jacob navia | last post by:
http://slashdot.org/ "The leaner, lighter, faster, and most importantly, BSD Licensed, Compiler PCC has been imported into OpenBSD's CVS and NetBSD's pkgsrc. The compiler is based on the...
1
by: rkcons | last post by:
Any ideals what would cause this ? Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.