[vala/0.48] codegen: Access of stack allocated struct is guaranteed to be non null
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.48] codegen: Access of stack allocated struct is guaranteed to be non null
- Date: Thu, 17 Feb 2022 08:47:05 +0000 (UTC)
commit 55d2050ec4862cba66fcd29adb7b681eef0df643
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Mon Jan 24 10:17:46 2022 +0100
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
codegen/valaccodebasemodule.vala | 2 ++
vala/valaaddressofexpression.vala | 4 ++++
vala/valamemberaccess.vala | 7 ++++++-
3 files changed, 12 insertions(+), 1 deletion(-)
---
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 {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]