From: Rico Tzschichholz Date: Mon, 24 Jan 2022 09:17:46 +0000 (+0100) Subject: codegen: Access of stack allocated struct is guaranteed to be non null X-Git-Tag: 0.52.11~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74c004ef9f8857c57d450c79faf0448ce314c365;p=thirdparty%2Fvala.git 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 --- 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 {