]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Access of inline allocated array is guaranteed to be non null
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 23 Jan 2022 17:46:48 +0000 (18:46 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 9 Feb 2022 21:19:10 +0000 (22:19 +0100)
and improve null check for container in slice expression

Found by -Werror=address with GCC 12

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

codegen/valaccodearraymodule.vala
codegen/valaccodebasemodule.vala
vala/valamemberaccess.vala

index 0a76c72cba4612f0452cbd410aeeb396d14eac61..c7df733e3904616a3ee0ca816f0bc766ca117769 100644 (file)
@@ -210,6 +210,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                var splicelen = new CCodeBinaryExpression (CCodeBinaryOperator.MINUS, cstop, cstart);
 
                set_cvalue (expr, cstartpointer);
+               ((GLibValue) expr.target_value).non_null = get_non_null (expr.container.target_value);
                // Make sure no previous length values are preserved
                set_array_length (expr, splicelen);
        }
index 77eff58776901ae86e4f9d6f47923caffc894fb2..3c76e5c10ca3156d6a9e0045ec54d78aa314a86b 100644 (file)
@@ -4766,6 +4766,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                        return store_temp_value (new GLibValue (type, ccall), node);
                } else {
+                       CCodeExpression ccallarg;
+                       if (node is SliceExpression) {
+                               ccallarg = cexpr;
+                               cexpr = get_cvalue (((SliceExpression) node).container);
+                       } else {
+                               ccallarg = cexpr;
+                       }
                        var cnotnull = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, cexpr, new CCodeConstant ("NULL"));
                        if (type is GenericType) {
                                // dup functions are optional for type parameters
@@ -4775,9 +4782,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                        if (type is GenericType) {
                                // cast from gconstpointer to gpointer as GBoxedCopyFunc expects gpointer
-                               ccall.add_argument (new CCodeCastExpression (cexpr, get_ccode_name (pointer_type)));
+                               ccall.add_argument (new CCodeCastExpression (ccallarg, get_ccode_name (pointer_type)));
                        } else {
-                               ccall.add_argument (cexpr);
+                               ccall.add_argument (ccallarg);
                        }
 
                        if (type is ArrayType) {
index 5f90a8449976b3118740406e188d3e0cc17cb3f3..a56b7cf782a4394968ec1cedf4294314aba74cdf 100644 (file)
@@ -193,8 +193,11 @@ public class Vala.MemberAccess : Expression {
 
        public override bool is_non_null () {
                unowned Constant? c = symbol_reference as Constant;
+               unowned LocalVariable? l = symbol_reference as LocalVariable;
                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);
                } else {
                        return false;
                }