[vala/0.52] codegen: Access of stack allocated struct is guaranteed to be non null



commit 74c004ef9f8857c57d450c79faf0448ce314c365
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Mon Jan 24 10:17:46 2022 +0100

    codegen: Access of stack allocated struct is guaranteed to be non null
    
    Found by -Werror=address with GCC 12
    
    See https://gitlab.gnome.org/GNOME/vala/issues/1282

 codegen/valaccodebasemodule.vala  | 2 ++
 vala/valaaddressofexpression.vala | 4 ++++
 vala/valamemberaccess.vala        | 7 ++++++-
 3 files changed, 12 insertions(+), 1 deletion(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 3c76e5c10..6c1a14910 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5516,6 +5516,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        innercexpr = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, innercexpr);
                }
                set_cvalue (expr, new CCodeCastExpression (innercexpr, get_ccode_name (expr.type_reference)));
+               //TODO Use get_non_null (expr.inner.target_value)
+               ((GLibValue) expr.target_value).non_null = expr.is_non_null ();
 
                if (expr.type_reference is DelegateType) {
                        var target = get_delegate_target (expr.inner);
diff --git a/vala/valaaddressofexpression.vala b/vala/valaaddressofexpression.vala
index ff542835b..dbe9cff1a 100644
--- a/vala/valaaddressofexpression.vala
+++ b/vala/valaaddressofexpression.vala
@@ -82,6 +82,10 @@ public class Vala.AddressofExpression : Expression {
                return inner.is_accessible (sym);
        }
 
+       public override bool is_non_null () {
+               return inner.is_non_null ();
+       }
+
        public override bool check (CodeContext context) {
                if (checked) {
                        return !error;
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 35c5bdc98..ab671d026 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -198,7 +198,12 @@ public class Vala.MemberAccess : Expression {
                if (c != null) {
                        return (c is EnumValue || !c.type_reference.nullable);
                } else if (l != null) {
-                       return (l.variable_type is ArrayType && ((ArrayType) 
l.variable_type).inline_allocated);
+                       unowned DataType type = l.variable_type;
+                       if (type is ArrayType) {
+                               return ((ArrayType) type).inline_allocated;
+                       } else {
+                               return type.is_real_non_null_struct_type () || type.is_non_null_simple_type 
();
+                       }
                } else if (m != null) {
                        return (m.binding == MemberBinding.STATIC || prototype_access);
                } else {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]