diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUnsafeModifier.cs b/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUnsafeModifier.cs index 04504b4b7..fb3d52b6f 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUnsafeModifier.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUnsafeModifier.cs @@ -16,17 +16,15 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +using System.Linq; using ICSharpCode.Decompiler.CSharp.Syntax; +using ICSharpCode.Decompiler.Semantics; using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.Decompiler.CSharp.Transforms { public class IntroduceUnsafeModifier : DepthFirstAstVisitor, IAstTransform { - public static readonly object PointerArithmeticAnnotation = new PointerArithmetic(); - - sealed class PointerArithmetic {} - public void Run(AstNode compilationUnit, TransformContext context) { compilationUnit.AcceptVisitor(this); @@ -67,8 +65,11 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms { bool result = base.VisitUnaryOperatorExpression(unaryOperatorExpression); if (unaryOperatorExpression.Operator == UnaryOperatorType.Dereference) { - BinaryOperatorExpression bop = unaryOperatorExpression.Expression as BinaryOperatorExpression; - if (bop != null && bop.Operator == BinaryOperatorType.Add && bop.Annotation() != null) { + var bop = unaryOperatorExpression.Expression as BinaryOperatorExpression; + if (bop != null && bop.Operator == BinaryOperatorType.Add + && bop.GetResolveResult() is OperatorResolveResult orr + && orr.Operands.FirstOrDefault()?.Type.Kind == TypeKind.Pointer) + { // transform "*(ptr + int)" to "ptr[int]" IndexerExpression indexer = new IndexerExpression(); indexer.Target = bop.Left.Detach();