]> 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, 9 Feb 2022 21:20:10 +0000 (22:20 +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 3c76e5c10ca3156d6a9e0045ec54d78aa314a86b..6c1a149100c50633653614d2e64be23b3f1ae323 100644 (file)
@@ -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);
index ff542835be2f614b4148252caeae114a6ea5b743..dbe9cff1aa8930e7628965f940a282134370fe15 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 35c5bdc984a28c2677696e43c87fdcb6c0f3f3c5..ab671d026bb9580084edb17e68d7b822464d36a2 100644 (file)
@@ -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 {