]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Access of stack allocated struct is guaranteed to be non null
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 24 Jan 2022 09:17:46 +0000 (10:17 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 16 Feb 2022 17:32:14 +0000 (18:32 +0100)
Found by -Werror=address with GCC 12

See https://gitlab.gnome.org/GNOME/vala/issues/1282

codegen/valaccodebasemodule.vala
vala/valaaddressofexpression.vala
vala/valamemberaccess.vala

index 9fe07e5382bcfbaa8ba8f256a597b6591a9c9318..39abb0f417128a795834a1fe0e5397062a801875 100644 (file)
@@ -5435,6 +5435,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);
index 9e89b03bd09e3b91fdbb93d134cc5fb54e7d41e5..0defcd96a4d2c160734de012102557f86dc62bbd 100644 (file)
@@ -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;
index f15c094ede94cc111f4e4fd1a48046fb9c445a5f..9282fd28f911ddaf5bbbfde16f64db065548affd 100644 (file)
@@ -197,7 +197,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 {