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

Merge main to main-vs-deps #56939

Merged
merged 5 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,22 @@ private BoundExpression CheckValue(BoundExpression expr, BindValueKind valueKind
return expr;
}
break;

case BoundKind.PointerIndirectionOperator:
if ((valueKind & BindValueKind.RefersToLocation) == BindValueKind.RefersToLocation)
{
var pointerIndirection = (BoundPointerIndirectionOperator)expr;
expr = pointerIndirection.Update(pointerIndirection.Operand, refersToLocation: true, pointerIndirection.Type);
}
break;

case BoundKind.PointerElementAccess:
if ((valueKind & BindValueKind.RefersToLocation) == BindValueKind.RefersToLocation)
{
var elementAccess = (BoundPointerElementAccess)expr;
expr = elementAccess.Update(elementAccess.Expression, elementAccess.Index, elementAccess.Checked, refersToLocation: true, elementAccess.Type);
}
break;
}

bool hasResolutionErrors = false;
Expand Down
6 changes: 3 additions & 3 deletions src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5915,7 +5915,7 @@ private BoundExpression BindMemberAccess(
}
else
{
boundLeft = new BoundPointerIndirectionOperator(exprSyntax, boundLeft, pointedAtType, hasErrors)
boundLeft = new BoundPointerIndirectionOperator(exprSyntax, boundLeft, refersToLocation: false, pointedAtType, hasErrors)
{
WasCompilerGenerated = true, // don't interfere with the type info for exprSyntax.
};
Expand Down Expand Up @@ -7693,7 +7693,7 @@ private BoundExpression BindPointerElementAccess(ExpressionSyntax node, BoundExp
Error(diagnostics, ErrorCode.ERR_PtrIndexSingle, node);
}
return new BoundPointerElementAccess(node, expr, BadExpression(node, BuildArgumentsForErrorRecovery(analyzedArguments)).MakeCompilerGenerated(),
CheckOverflowAtRuntime, pointedAtType, hasErrors: true);
CheckOverflowAtRuntime, refersToLocation: false, pointedAtType, hasErrors: true);
}

if (pointedAtType.IsVoidType())
Expand All @@ -7705,7 +7705,7 @@ private BoundExpression BindPointerElementAccess(ExpressionSyntax node, BoundExp
BoundExpression index = arguments[0];

index = ConvertToArrayIndex(index, diagnostics, allowIndexAndRange: false);
return new BoundPointerElementAccess(node, expr, index, CheckOverflowAtRuntime, pointedAtType, hasErrors);
return new BoundPointerElementAccess(node, expr, index, CheckOverflowAtRuntime, refersToLocation: false, pointedAtType, hasErrors);
}

private static bool ReportRefOrOutArgument(AnalyzedArguments analyzedArguments, BindingDiagnosticBag diagnostics)
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2322,7 +2322,7 @@ private BoundExpression BindPointerIndirectionExpression(PrefixUnaryExpressionSy
bool hasErrors;
BindPointerIndirectionExpressionInternal(node, operand, diagnostics, out pointedAtType, out hasErrors);

return new BoundPointerIndirectionOperator(node, operand, pointedAtType ?? CreateErrorType(), hasErrors);
return new BoundPointerIndirectionOperator(node, operand, refersToLocation: false, pointedAtType ?? CreateErrorType(), hasErrors);
}

private static void BindPointerIndirectionExpressionInternal(CSharpSyntaxNode node, BoundExpression operand, BindingDiagnosticBag diagnostics, out TypeSymbol pointedAtType, out bool hasErrors)
Expand Down
8 changes: 8 additions & 0 deletions src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@
<!-- Non-null type is required for this node kind -->
<Field Name="Type" Type="TypeSymbol" Override="true" Null="disallow"/>
<Field Name="Operand" Type="BoundExpression"/>
<!-- Used by emit to determine whether this pointer indirection is by value or by ref. If true, emit
will emit the address of the target, and not actually perform an indirect load (in practice this just
means emitting the Operand alone). -->
<Field Name="RefersToLocation" Type="bool"/>
</Node>
<Node Name="BoundPointerElementAccess" Base="BoundExpression">
<!-- Non-null type is required for this node kind -->
Expand All @@ -350,6 +354,10 @@
<Field Name="Expression" Type="BoundExpression"/>
<Field Name="Index" Type="BoundExpression"/>
<Field Name="Checked" Type="bool"/>
<!-- Used by emit to determine whether this pointer element access is by value or by ref. If true, emit
will emit the address of the target, and not actually perform an indirect load (in practice this just
means emitting the Operand alone). -->
<Field Name="RefersToLocation" Type="bool"/>
</Node>

<Node Name="BoundFunctionPointerInvocation" Base="BoundExpression">
Expand Down
6 changes: 5 additions & 1 deletion src/Compilers/CSharp/Portable/CodeGen/EmitExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,11 @@ private void EmitAddressOfExpression(BoundAddressOfOperator expression, bool use
private void EmitPointerIndirectionOperator(BoundPointerIndirectionOperator expression, bool used)
{
EmitExpression(expression.Operand, used: true);
EmitLoadIndirect(expression.Type, expression.Syntax);
if (!expression.RefersToLocation)
{
EmitLoadIndirect(expression.Type, expression.Syntax);
}

EmitPopIfUnused(used);
}

Expand Down
36 changes: 22 additions & 14 deletions src/Compilers/CSharp/Portable/Generated/BoundNodes.xml.Generated.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public override BoundNode VisitFixedStatement(BoundFixedStatement node)
cleanup[i] = _factory.Assignment(_factory.Local(pinnedTemp), new BoundPointerIndirectionOperator(
_factory.Syntax,
_factory.Default(new PointerTypeSymbol(pinnedTemp.TypeWithAnnotations)),
refersToLocation: false,
pinnedTemp.Type),
isRef: true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ private BoundExpression RewritePointerElementAccess(BoundPointerElementAccess no
return new BoundPointerIndirectionOperator(
node.Syntax,
rewrittenExpression,
node.RefersToLocation,
node.Type);
}

Expand Down Expand Up @@ -78,6 +79,7 @@ private BoundExpression RewritePointerElementAccess(BoundPointerElementAccess no
method: null,
constrainedToTypeOpt: null,
isPointerElementAccess: true), //see RewriterPointerNumericOperator
node.RefersToLocation,
node.Type);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1177,14 +1177,14 @@ public override BoundNode VisitPointerElementAccess(BoundPointerElementAccess no
builder = expressionBuilder;
}

return UpdateExpression(builder, node.Update(expression, index, node.Checked, node.Type));
return UpdateExpression(builder, node.Update(expression, index, node.Checked, node.RefersToLocation, node.Type));
}

public override BoundNode VisitPointerIndirectionOperator(BoundPointerIndirectionOperator node)
{
BoundSpillSequenceBuilder builder = null;
var operand = VisitExpression(ref builder, node.Operand);
return UpdateExpression(builder, node.Update(operand, node.Type));
return UpdateExpression(builder, node.Update(operand, node.RefersToLocation, node.Type));
}

public override BoundNode VisitSequence(BoundSequence node)
Expand Down
Loading