-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Conversation
@dotnet/roslyn-compiler Please review. @MattGertz Please approve for update 3. In the meantime, I will get approval from the compat council. |
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) { } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use AssertTheseDiagnostics API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@AlekseyTs The PR is updated with all the scenarios we discussed. |
@@ -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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@AlekseyTs Pushed the fix we just discussed. |
LGTM |
Thanks a lot. @dotnet/roslyn-compiler Could I have a second review for this update 3 bug? |
@MattGertz All checks are green. I have one review approval and one compat approval. I'll get the second one of each shortly. |
LGTM |
There are two scenarios:
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).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.Fixes this Watson crash.