Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 217740: don't crash when emitting or loading a DateTimeConstant(-1) attribute #11536

Merged
merged 13 commits into from May 26, 2016

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented May 24, 2016

There are two scenarios:

  1. Compiling source that includes a DateTimeConstant(-1).
    This is the scenario reported by the Watson bug.
    The fix in CommonAttributeData.cs restores the behavior of the native compiler (nil .param, and DateTimeConstantAttribute(-1), as shown below).
  2. Loading such attribute from metadata. Inspection of Rolsyn code found this issue, which was then confirmed to exists.
    Roslyn would crash when encountering such an attribute (and the optional flag is set on the parameter).
    In such a case, the native compilers would instead succeed, although the resulting binary would crash.
    The fix to Rolsyn in PEModule.cs makes the loading of such an attribute to load a default value instead. This change breaks back compat and will be submitted to the compat-council shortly.
                .param [1]
                .custom instance void [mscorlib]System.Runtime.CompilerServices.DateTimeConstantAttribute::.ctor(int64) = (
                                01 00 ff ff ff ff ff ff ff ff 00 00
                )

Fixes this Watson crash.

@jcouv jcouv added Area-Compilers Tenet-Reliability Customer telemetry indicates that the product is failing in a crash/hang/dataloss manner. labels May 24, 2016
@jcouv jcouv self-assigned this May 24, 2016
@jcouv
Copy link
Member Author

jcouv commented May 24, 2016

@dotnet/roslyn-compiler Please review.

@MattGertz Please approve for update 3.

In the meantime, I will get approval from the compat council.

@MattGertz
Copy link
Contributor

This would meet the bar, but ping me again when compat/PRs/testing all aligns.


public class Bar
{
public void Method([DateTimeConstant(-1)]DateTime p1) { }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to have a test that tries to consume this method without providing the argument

  • in the same compilation
  • in another compilation, referencing metadata produced by this one.

Is behavior for these scenarios consistent with native compiler?

Copy link
Contributor

@AlekseyTs AlekseyTs May 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should test the same when default value is explicitly set through the special syntax on the parameter.
Should test similar scenarios for VB too.

void m1([DateTimeConstant(-1)] DateTime x = default(DateTime))

In reply to: 64497023 [](ancestors = 64497023)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What we need to watch out for in cases when values are also provided through special syntax is that we wouldn't try to emit two or more DateTimeConstantValue attributes.


In reply to: 64497476 [](ancestors = 64497476,64497023)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already manually verified the behavior when referencing metadata. The behavior is consistent, an error is reported (C# used to report error CS1501: No overload for method 'Method' takes 0 arguments and VB used to report error BC30455: Argument not specified for parameter 'p' of 'Public Function Method(p As Date = #12:00:00 AM#) As Date').
I cannot do compilation reference with native compiler.

I added a test for both scenarios (C# and VB).
I'll add test for "double attribute" concern.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "double attribute" scenario works fine in C# (only one is emitted), but VB emits two. I'll stop by.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it looks like C# never synthesizes the attribute.


In reply to: 64610028 [](ancestors = 64610028)

Dim libCompRef = New VisualBasicCompilationReference(libComp)

Dim comp2 = CreateCompilationWithMscorlib(source2, references:={libCompRef})
comp2.VerifyDiagnostics(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use AssertTheseDiagnostics API

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@jcouv
Copy link
Member Author

jcouv commented May 26, 2016

@AlekseyTs The PR is updated with all the scenarios we discussed.
I wrote a new summary for the compat council.

@@ -332,8 +332,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Dim data = GetEarlyDecodedWellKnownAttributeData()
If data IsNot Nothing Then
Dim attrValue = data.DefaultParameterValue
If Not attrValue.IsBad AndAlso
attrValue <> ConstantValue.Unset AndAlso
If attrValue <> ConstantValue.Unset AndAlso
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there similar code for constant fields?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I'll check it out.

Also, I noticed that some paths still check for ConstantValue.IsBad, for example DecodeDefaultParameterValueAttribute. I'll check those out too.

@jcouv
Copy link
Member Author

jcouv commented May 26, 2016

@AlekseyTs Pushed the fix we just discussed.

@AlekseyTs
Copy link
Contributor

LGTM

@jcouv
Copy link
Member Author

jcouv commented May 26, 2016

Thanks a lot.

@dotnet/roslyn-compiler Could I have a second review for this update 3 bug?

@jcouv
Copy link
Member Author

jcouv commented May 26, 2016

@MattGertz All checks are green. I have one review approval and one compat approval. I'll get the second one of each shortly.
Can you approve also?

@VSadov
Copy link
Member

VSadov commented May 26, 2016

LGTM

@jcouv jcouv merged commit dd21101 into dotnet:master May 26, 2016
@jcouv jcouv added the Tenet-Compatibility Violation of forwards/backwards compatibility in a design-time piece. label Jun 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved to merge Area-Compilers cla-already-signed Tenet-Compatibility Violation of forwards/backwards compatibility in a design-time piece. Tenet-Reliability Customer telemetry indicates that the product is failing in a crash/hang/dataloss manner.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants