Crash-bug in the VS 2008 C# compiler


S

Sune Foldager

Greetings,

When compiling the following example, Visual Studio 2008 (or rather the compiler
it invokes), crashes. The most reduced example I could come up with to provoke
this bug, is the following (compile as a console application, for instance):

----------
using System;

namespace Test
{
class Program
{
static void Main(string[] args)
{
var o = new Object();

// If this line is removed, the crash goes away.
lock (o) ;

// Extra code at this point (at least to some extent) won't affect
the crash.

lock (o) // <-- If we use { } around the inner statement, the crash
goes away.
if(true) // <-- This line can also be lock(o), while(false) or something
else.
{
int i; // <-- If no variable is declared, the crash goes away.
}
}
}
}
----------

The bug is, somewhat surprisingly, reported as being in the EMITIL phase:

------ Build started: Project: Test, Configuration: Debug Any CPU ------
C:\Windows\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702
/errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"C:\Program Files\Reference
Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"C:\Program
Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll"
/reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll
/reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll
/reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll"
/debug+ /debug:full /filealign:512 /optimize- /out:blush:bj\Debug\Test.exe /target:exe
Program.cs Properties\AssemblyInfo.cs
C:\Users\sune.foldager\Test\Program.cs(12,16): warning CS0642: Possible mistaken
empty statement
C:\Users\sune.foldager\Test\Program.cs(19,15): warning CS0168: The variable
'i' is declared but never used
error CS0583: Internal Compiler Error (0xc0000005 at address 65790140): likely
culprit is 'EMITIL'.

An internal error has occurred in the compiler. To work around this problem,
try simplifying or changing the program near the locations listed below.
Locations at the top of the list are closer to the point at which the internal
error occurred. Errors such as this can be reported to Microsoft by using
the /errorreport option.

C:\Users\sune.foldager\Test\Program.cs(7,17): error CS0584: Internal Compiler
Error: stage 'EMITIL' symbol 'Test.Program.Main(string[])'
C:\Users\sune.foldager\Test\Program.cs(7,17): error CS0584: Internal Compiler
Error: stage 'CODEGEN' symbol 'Test.Program.Main(string[])'
C:\Users\sune.foldager\Test\Program.cs(7,17): error CS0584: Internal Compiler
Error: stage 'COMPILE' symbol 'Test.Program.Main(string[])'
C:\Users\sune.foldager\Test\Program.cs(7,17): error CS0584: Internal Compiler
Error: stage 'COMPILE' symbol 'Test.Program.Main(string[])'
C:\Users\sune.foldager\Test\Program.cs(5,9): error CS0584: Internal Compiler
Error: stage 'COMPILE' symbol 'Test.Program'
C:\Users\sune.foldager\Test\Program.cs(3,11): error CS0584: Internal Compiler
Error: stage 'COMPILE' symbol 'Test'
C:\Users\sune.foldager\Test\Program.cs: error CS0584: Internal Compiler Error:
stage 'COMPILE' symbol '<global namespace>'
C:\Users\sune.foldager\Test\Program.cs: error CS0586: Internal Compiler Error:
stage 'COMPILE'
error CS0587: Internal Compiler Error: stage 'COMPILE'
error CS0587: Internal Compiler Error: stage 'EMIT'
error CS0587: Internal Compiler Error: stage 'BEGIN'

Compile complete -- 12 errors, 2 warnings
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========


Sincerly,
Sune Foldager
Edlund A/
 
Ad

Advertisements

M

Marc Gravell

With 2008/3.5-SP1-beta installed I just get:

Warning 1 Possible mistaken empty statement

So I think this is already fixed. You might like to try SP1-beta on a
spare machine and verify.

Marc
 
M

Marc Gravell

Actually, one curiosity of how it behaves in SP1-beta; the first time
you compile, you also get:

Warning 2 The variable 'i' is declared but never used

However, on subsequent compiles this disappears.

As with your other post, "connect" is the probably the next place for
this (if you are concerned by the above glitch).

Marc
 
S

Sune Foldager

Hello Marc,
So I think this is already fixed. You might like to try SP1-beta on a
spare machine and verify.

Yes, I see that connect-bug #340383 is similar, with embedded statements,
and is reported as fixed in internal builds.

-- Sune
 
J

Jialiang Ge [MSFT]

Good morning, Sune. Welcome to Microsoft Newsgroup Support Service!

I have reproduce the compiler error with your example code. Sune, you
accurately spotted the connect bug #340383
https://connect.microsoft.com/Visua...Feedback.aspx?FeedbackID=340383&wa=wsignin1.0
The product team had recognized the issue in this feedback link and of
yours, and checked the fix into Visual Studio 2008 SP1 beta:
http://msdn.microsoft.com/en-us/vstudio/products/cc533447.aspx

Below is more background information about this VS compiler problem:

ISSUE:

When we have two lock statements in the same block with both a single
embedded statement and the second lock introduces a variable in its
statement, the compiler crashes. During the binding of the lock statement,
the lookup erroneously returns a scope that is not for the lock statement.
Consider this simplified repro case:

static void Main()
{
lock (lockObj)
Console.WriteLine("First lock");
lock (lockObj)
try { Console.WriteLine("Second lock"); }
catch (Exception ex) { Console.WriteLine(ex); }
}

We report the variable "ex" as unused and ILgen cannot find its type, which
is the cause of the crash. The root cause, however, is the scope lookup for
the lock statement.

FIX:

The fix has been checked into the Visual Studio 2008 SP1 beta.

Sune, I want to extend my gratitude to you for this great findings. It is
the inputs of numerous intelligent and warmhearted customers like you, that
improve the quality of Visual Studio. Thank you again! If you have any other
concerns, please DON'T hesitate to tell me.

Thanks,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jialiang Ge [MSFT]

Hello Sune,

How are you today? I'm writing to see whether there's anything else I can
do for you in this post. Sune, I notice you reported another Visual Studio
problem to us in the post "Bug in
System.Windows.Forms.ToolStrip.ProcessCmdKey". Thank you very much for all
these ardent feedbacks! If you have any questions or concerns on our
products, or our support services, please DON'T hesitate to tell me.

Thanks
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Ad

Advertisements

B

Ben Voigt [C++ MVP]

Marc Gravell said:
Actually, one curiosity of how it behaves in SP1-beta; the first time you
compile, you also get:

Warning 2 The variable 'i' is declared but never used

However, on subsequent compiles this disappears.

This is most likely minimal rebuild at work.

On any given compile, you only get the list of warnings from the projects
which changed and therefore had to be rebuilt. To see all warnings, run
"Rebuild All".
 
Ad

Advertisements

J

Jialiang Ge [MSFT]

Yes. To reproduce this disappearance of the warning message, we can use an
even simpler code:

static void Main(string[] args)
{
int a;
}

Visual Studio gives an warning "The variable 'a' is declared but never
used" in the first build. When you build it again, the warning disappears.
Both "Rebuild All" and editing the source file to update the file's
timestamp result in the appearance of the warning. Visual Studio calls
MSBuild to build the project, and MSBuild can compare the timestamps of the
input files with the timestamps of the output files and determine whether
to skip, build, or partially rebuild a target.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top