diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs index fa9dc7a3..95e0284e 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs @@ -1530,7 +1530,9 @@ private void VisitImplicitCastExpr(ImplicitCastExpr implicitCastExpr) // value type, which has no implicit pointer conversion, so take its address to // bind it to a pointer. A compatible-mode fixed buffer decays on its own, and // array locals (managed arrays) or string literals must not be addressed here. - if (!Config.GenerateCompatibleCode && (subExpr is MemberExpr) && (subExpr.Type.CanonicalType is ConstantArrayType) && (implicitCastExpr.Type.CanonicalType is PointerType)) + // A subscripted field (`arr[i]`) indexes the inline array in place, so the decay + // there is an lvalue that must not be addressed. + if (!Config.GenerateCompatibleCode && (subExpr is MemberExpr) && (subExpr.Type.CanonicalType is ConstantArrayType) && (implicitCastExpr.Type.CanonicalType is PointerType) && !IsPrevContextStmt(out _, out _)) { outputBuilder.Write('&'); } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Compatible.Unix.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Compatible.Unix.cs index 9c40df1c..a02d3c77 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Compatible.Unix.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Compatible.Unix.cs @@ -16,6 +16,7 @@ public static unsafe partial class Methods public static void MyFunction([NativeTypeName("struct MyStruct *")] MyStruct* pStruct) { MyOtherFunction(pStruct->Data); + pStruct->Data[15] = 1; } } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Compatible.Windows.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Compatible.Windows.cs index 2b2853e0..d89c157a 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Compatible.Windows.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Compatible.Windows.cs @@ -16,6 +16,7 @@ public static unsafe partial class Methods public static void MyFunction([NativeTypeName("struct MyStruct *")] MyStruct* pStruct) { MyOtherFunction(pStruct->Data); + pStruct->Data[15] = 1; } } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Default.Unix.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Default.Unix.cs index d6e31c8b..12598cb6 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Default.Unix.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Default.Unix.cs @@ -23,6 +23,7 @@ public static unsafe partial class Methods public static void MyFunction([NativeTypeName("struct MyStruct *")] MyStruct* pStruct) { MyOtherFunction(&pStruct->Data); + pStruct->Data[15] = 1; } } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Default.Windows.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Default.Windows.cs index 5b5f6d5f..f4949ee0 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Default.Windows.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Default.Windows.cs @@ -23,6 +23,7 @@ public static unsafe partial class Methods public static void MyFunction([NativeTypeName("struct MyStruct *")] MyStruct* pStruct) { MyOtherFunction(&pStruct->Data); + pStruct->Data[15] = 1; } } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Latest.Unix.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Latest.Unix.cs index d6e31c8b..12598cb6 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Latest.Unix.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Latest.Unix.cs @@ -23,6 +23,7 @@ public static unsafe partial class Methods public static void MyFunction([NativeTypeName("struct MyStruct *")] MyStruct* pStruct) { MyOtherFunction(&pStruct->Data); + pStruct->Data[15] = 1; } } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Latest.Windows.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Latest.Windows.cs index 5b5f6d5f..f4949ee0 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Latest.Windows.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Latest.Windows.cs @@ -23,6 +23,7 @@ public static unsafe partial class Methods public static void MyFunction([NativeTypeName("struct MyStruct *")] MyStruct* pStruct) { MyOtherFunction(&pStruct->Data); + pStruct->Data[15] = 1; } } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Preview.Unix.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Preview.Unix.cs index d6e31c8b..12598cb6 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Preview.Unix.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Preview.Unix.cs @@ -23,6 +23,7 @@ public static unsafe partial class Methods public static void MyFunction([NativeTypeName("struct MyStruct *")] MyStruct* pStruct) { MyOtherFunction(&pStruct->Data); + pStruct->Data[15] = 1; } } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Preview.Windows.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Preview.Windows.cs index 5b5f6d5f..f4949ee0 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Preview.Windows.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.CSharp.Preview.Windows.cs @@ -23,6 +23,7 @@ public static unsafe partial class Methods public static void MyFunction([NativeTypeName("struct MyStruct *")] MyStruct* pStruct) { MyOtherFunction(&pStruct->Data); + pStruct->Data[15] = 1; } } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Compatible.Unix.xml b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Compatible.Unix.xml index 8cd5dace..10024584 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Compatible.Unix.xml +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Compatible.Unix.xml @@ -18,7 +18,8 @@ MyStruct* - MyOtherFunction(pStruct->Data); + MyOtherFunction(pStruct->Data); + pStruct->Data[15] = 1; diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Compatible.Windows.xml b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Compatible.Windows.xml index 15dc30e5..39153264 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Compatible.Windows.xml +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Compatible.Windows.xml @@ -18,7 +18,8 @@ MyStruct* - MyOtherFunction(pStruct->Data); + MyOtherFunction(pStruct->Data); + pStruct->Data[15] = 1; diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Default.Unix.xml b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Default.Unix.xml index 296fd096..d05ddb3d 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Default.Unix.xml +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Default.Unix.xml @@ -24,7 +24,8 @@ MyStruct* - MyOtherFunction(&pStruct->Data); + MyOtherFunction(&pStruct->Data); + pStruct->Data[15] = 1; diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Default.Windows.xml b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Default.Windows.xml index 37511c1b..2f1f894b 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Default.Windows.xml +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Default.Windows.xml @@ -24,7 +24,8 @@ MyStruct* - MyOtherFunction(&pStruct->Data); + MyOtherFunction(&pStruct->Data); + pStruct->Data[15] = 1; diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Latest.Unix.xml b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Latest.Unix.xml index 296fd096..d05ddb3d 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Latest.Unix.xml +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Latest.Unix.xml @@ -24,7 +24,8 @@ MyStruct* - MyOtherFunction(&pStruct->Data); + MyOtherFunction(&pStruct->Data); + pStruct->Data[15] = 1; diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Latest.Windows.xml b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Latest.Windows.xml index 37511c1b..2f1f894b 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Latest.Windows.xml +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Latest.Windows.xml @@ -24,7 +24,8 @@ MyStruct* - MyOtherFunction(&pStruct->Data); + MyOtherFunction(&pStruct->Data); + pStruct->Data[15] = 1; diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Preview.Unix.xml b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Preview.Unix.xml index 296fd096..d05ddb3d 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Preview.Unix.xml +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Preview.Unix.xml @@ -24,7 +24,8 @@ MyStruct* - MyOtherFunction(&pStruct->Data); + MyOtherFunction(&pStruct->Data); + pStruct->Data[15] = 1; diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Preview.Windows.xml b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Preview.Windows.xml index 37511c1b..2f1f894b 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Preview.Windows.xml +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/Baselines/FunctionDeclarationBodyImport/ArrayFieldToPointerArgumentTest.Xml.Preview.Windows.xml @@ -24,7 +24,8 @@ MyStruct* - MyOtherFunction(&pStruct->Data); + MyOtherFunction(&pStruct->Data); + pStruct->Data[15] = 1; diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/FunctionDeclarationBodyImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/FunctionDeclarationBodyImportTest.cs index 857ca648..5bdecde7 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/FunctionDeclarationBodyImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Baseline/FunctionDeclarationBodyImportTest.cs @@ -60,6 +60,7 @@ struct MyStruct void MyFunction(struct MyStruct* pStruct) { MyOtherFunction(pStruct->Data); + pStruct->Data[15] = 1; } ";