summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2022-01-24 10:17:46 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2022-02-16 18:32:14 +0100
commit55d2050ec4862cba66fcd29adb7b681eef0df643 (patch)
tree6957c782442a80c978172f8f5ececd70a17365a0
parent1201c5fbb97cde460768faebfd2378d26c3ec2e9 (diff)
downloadvala-55d2050ec4862cba66fcd29adb7b681eef0df643.tar.gz
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
-rw-r--r--codegen/valaccodebasemodule.vala2
-rw-r--r--vala/valaaddressofexpression.vala4
-rw-r--r--vala/valamemberaccess.vala7
3 files changed, 12 insertions, 1 deletions
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 9fe07e538..39abb0f41 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -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);
diff --git a/vala/valaaddressofexpression.vala b/vala/valaaddressofexpression.vala
index 9e89b03bd..0defcd96a 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 f15c094ed..9282fd28f 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -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 {