473,498 Members | 1,528 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VC++ .NET 2003: Access violation with /O2 compiler switch; no AV with /O1

VC++ .NET 2003: Access violation with /O2 compiler switch; no AV with /O

Hi
I'm in the process of narrowing down a problem, and I have reduced the code involved to the following
If someone could do the following and verify what I am seeing (and offer any insight!), I would appreciate it
Simply create a new "Win32 Console Project" in VC++ .NET 2003. On the "Application Settings" page, check the "Empty project" box. Click "Finish"
Add a new C++ source file, and paste in the following code
//=================
#include <strstream
#include <malloc.h

void Fn( void

_alloca( 100 )
std::ostrstream oss
oss << std::ends
oss.str()
oss.freeze( false )
throw std::string()
int main( void

tr

Fn()

catch( std::string&
return 0

//=================
I know the code doesn't make a whole lot of sense as it stands, but I am trying to reduce the code required to repro the problem to a minimum. When I build a "Release" build of the project (with the default project settings, which includes the default /O2, or "Maximize Speed" optimization) and run it, I get an AV in ostrstream::~ostrstream ("Access violation reading location 0x00000004"). Same result with /Ox ("Full Optimization"). However, if I change the optimization to /O1 ("Minimize Size") or /Od ("Disable [Optimizations]"), the code runs "just fine" (no AV)

If I do the same thing with VC++ .NET 2002, the code runs "just fine" with all optimization settings (/Od, /O1, /O2, /Ox)

Any thoughts?
Nov 17 '05 #1
3 4418
This definitely looks like a codegen bug. I was able to reproduce the crash
compiling the VC7.1, but the bug appears to be fixed in the Whidbey (VS.NET
2005) alpha. If this bug is causing you problems in production code, you
should contact Product Support Services to see if there's a
hotfix/QFE/workaround available.

-cd

Binary wrote:
VC++ .NET 2003: Access violation with /O2 compiler switch; no AV with
/O1

Hi,
I'm in the process of narrowing down a problem, and I have reduced
the code involved to the following.
If someone could do the following and verify what I am seeing (and
offer any insight!), I would appreciate it.
Simply create a new "Win32 Console Project" in VC++ .NET 2003. On
the "Application Settings" page, check the "Empty project" box.
Click "Finish".
Add a new C++ source file, and paste in the following code:
//==================
#include <strstream>
#include <malloc.h>

void Fn( void )
{
_alloca( 100 );
std::ostrstream oss;
oss << std::ends;
oss.str();
oss.freeze( false );
throw std::string();
}

int main( void )
{
try
{
Fn();
}
catch( std::string& )
{
}
return 0;
}
//==================
I know the code doesn't make a whole lot of sense as it stands, but I
am trying to reduce the code required to repro the problem to a
minimum. When I build a "Release" build of the project (with the
default project settings, which includes the default /O2, or
"Maximize Speed" optimization) and run it, I get an AV in
ostrstream::~ostrstream ("Access violation reading location
0x00000004"). Same result with /Ox ("Full Optimization"). However,
if I change the optimization to /O1 ("Minimize Size") or /Od
("Disable [Optimizations]"), the code runs "just fine" (no AV).

If I do the same thing with VC++ .NET 2002, the code runs "just fine"
with all optimization settings (/Od, /O1, /O2, /Ox).

Any thoughts?

Nov 17 '05 #2

"Binary" <an*******@discussions.microsoft.com> skrev i meddelandet
news:B8**********************************@microsof t.com...
VC++ .NET 2003: Access violation with /O2 compiler switch; no AV with /O1

Hi,
I'm in the process of narrowing down a problem, and I have reduced the code involved to the following. If someone could do the following and verify what I am seeing (and offer any insight!), I would appreciate it. Simply create a new "Win32 Console Project" in VC++ .NET 2003. On the "Application Settings" page, check the "Empty project" box. Click "Finish". Add a new C++ source file, and paste in the following code:
//==================
#include <strstream>
#include <malloc.h>

void Fn( void )
{
_alloca( 100 );
std::ostrstream oss;
oss << std::ends;
oss.str();
oss.freeze( false );
throw std::string();
}

int main( void )
{
try
{
Fn();
}
catch( std::string& )
{
}
return 0;
}
//==================
I know the code doesn't make a whole lot of sense as it stands, but I am trying to reduce the code required to repro the problem to a minimum. When
I build a "Release" build of the project (with the default project settings,
which includes the default /O2, or "Maximize Speed" optimization) and run
it, I get an AV in ostrstream::~ostrstream ("Access violation reading
location 0x00000004"). Same result with /Ox ("Full Optimization").
However, if I change the optimization to /O1 ("Minimize Size") or /Od
("Disable [Optimizations]"), the code runs "just fine" (no AV).
If I do the same thing with VC++ .NET 2002, the code runs "just fine" with all optimization settings (/Od, /O1, /O2, /Ox).
Any thoughts?


There are some limitations to the use of _alloca in the Visual Studio help.
One of these is:

"Security Note In Windows XP, if _alloca is called inside a try/catch
block, you must call _resetstkoflw in the catch block."

If /O2 happens to inline the functions call Fn(), then maybe _alloca
actually is inside the try/catch block?
Bo Persson

Nov 17 '05 #3
Binary wrote:
VC++ .NET 2003: Access violation with /O2 compiler switch; no AV with /O1 <snip>When I build a "Release" build of the project (with the default project settings, which includes the default /O2, or "Maximize Speed" optimization)


I can't say if using /O1 here avoided the problem or merely disguised it,
but many people consider /O1 a better default option than /O2. YMMV, but
after switching to /O1 years ago, I've run into very few optimizer bugs. In
addition, if "smaller code" is achieved to a significant degree, I'd
hypothesize that it can sometimes be faster due to cache and paging effects.
In any event, it's very likely fast enough, such that sticking with /O2 as
the default doesn't buy you much.

--
Doug Harrison
Microsoft MVP - Visual C++
Nov 17 '05 #4

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

Similar topics

11
4163
by: muser | last post by:
In the code I supplied before this one, the cause of the problem is an access violation error. When I run the debugger it skips into what I can only assume is the compilers version of my code. And...
5
3819
by: Mark | last post by:
The following code works with gnu compilers (ISO compliant declaration of the variable "i") void foo() { for (int i = 0; i < length; i++) { loop code.... } for (int i = 0; i < length; ...
6
2764
by: Ben Terry | last post by:
Hello, I have a VS 2003.NET solution which consists of four c++ unmanaged legacy projects. I am adding a new project to the solution which will be in c#. What do I need to do to my c++ projects...
4
1879
by: Alex | last post by:
Hi there I'm switching from VC++ 6.0 to VC++ .NET 2003. Since there is no stand-alone version of VC++ .NET 2003 Pro, I went and purchased the Standard version, which does not have an...
2
2512
by: Itjalve | last post by:
I have a heap problem in my com exe server. When i use windbg as the compiler in application verifier is windbg started and i can press 'g' and the server is running unitil i get the exception. ...
0
1958
by: Ganapathy | last post by:
I have COM dll code written in VC 6.0. When i tried compiling this code in VC 7, The MIDL cmpiler gets called twice. i.e. it initially compiles fully & immediately a line - 64 bit processing'...
1
2577
by: Robert Ludewig | last post by:
I have sucessfully imported and compiled a complex MFC 6.0 project from vc++6.0 (MFC6.0) into vc++ 8.0 (MFC 8.0). It contains several subprojects (libs and dlls). In vc++ 6.0 those project linked...
8
2292
by: Edward Diener | last post by:
By reuse, I mean a function in an assembly which is called in another assembly. By a mixed-mode function I mean a function whose signature has one or more CLR types and one or more non-CLR...
10
1882
by: Diego Martins | last post by:
I just discovered a serious issue when compiling code using auto_ptr<> and VC 8.0 consider some sort of create() function blahblah * create() { return new blahblah; } and a pretty auto_ptr
0
6998
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5460
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4586
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1416
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
651
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.