[vala/0.54] 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.54] codegen: Access of stack allocated struct is guaranteed to be non null
- Date: Wed, 9 Feb 2022 13:02:37 +0000 (UTC)
commit c1275e302300ed964e22f6e0ffa2d89d231945a4
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 ++
tests/structs/bug777194.c-expected | 8 ++++----
vala/valaaddressofexpression.vala | 4 ++++
vala/valamemberaccess.vala | 7 ++++++-
4 files changed, 16 insertions(+), 5 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 7dc89eaae..aca848020 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5593,6 +5593,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/tests/structs/bug777194.c-expected b/tests/structs/bug777194.c-expected
index 22a22e517..6f77df466 100644
--- a/tests/structs/bug777194.c-expected
+++ b/tests/structs/bug777194.c-expected
@@ -238,7 +238,7 @@ _vala_main (void)
_tmp4_ = tu;
_tmp4__length1 = tu_length1;
bar (_tmp4_, (gint) _tmp4__length1);
- _tmp5_ = (((guint8*) (&fstack)) != NULL) ? _vala_array_dup1 ((guint8*) (&fstack), sizeof (Foo) /
sizeof (guint8)) : ((guint8*) (&fstack));
+ _tmp5_ = _vala_array_dup1 ((guint8*) (&fstack), sizeof (Foo) / sizeof (guint8));
_tmp5__length1 = sizeof (Foo) / sizeof (guint8);
to = (g_free (to), NULL);
to = _tmp5_;
@@ -263,7 +263,7 @@ _vala_main (void)
_tmp11__length1 = tu_length1;
bar (_tmp11_, (gint) _tmp11__length1);
_tmp12_ = fstack;
- _tmp13_ = (((guint8*) (&_tmp12_)) != NULL) ? _vala_array_dup2 ((guint8*) (&_tmp12_), sizeof (Foo) /
sizeof (guint8)) : ((guint8*) (&_tmp12_));
+ _tmp13_ = _vala_array_dup2 ((guint8*) (&_tmp12_), sizeof (Foo) / sizeof (guint8));
_tmp13__length1 = sizeof (Foo) / sizeof (guint8);
to = (g_free (to), NULL);
to = _tmp13_;
@@ -310,7 +310,7 @@ _vala_main (void)
_tmp22_ = tu;
_tmp22__length1 = tu_length1;
_vala_assert (_tmp22__length1 == 4, "tu.length == 4");
- _tmp23_ = (((guint8*) (&i32)) != NULL) ? _vala_array_dup4 ((guint8*) (&i32), sizeof (gint32) / sizeof
(guint8)) : ((guint8*) (&i32));
+ _tmp23_ = _vala_array_dup4 ((guint8*) (&i32), sizeof (gint32) / sizeof (guint8));
_tmp23__length1 = sizeof (gint32) / sizeof (guint8);
to = (g_free (to), NULL);
to = _tmp23_;
@@ -332,7 +332,7 @@ _vala_main (void)
_tmp26_ = tu;
_tmp26__length1 = tu_length1;
_vala_assert (_tmp26__length1 == 8, "tu.length == 8");
- _tmp27_ = (((guint8*) (&u64)) != NULL) ? _vala_array_dup5 ((guint8*) (&u64), sizeof (guint64) /
sizeof (guint8)) : ((guint8*) (&u64));
+ _tmp27_ = _vala_array_dup5 ((guint8*) (&u64), sizeof (guint64) / sizeof (guint8));
_tmp27__length1 = sizeof (guint64) / sizeof (guint8);
to = (g_free (to), NULL);
to = _tmp27_;
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 d0253a1fe..798d79178 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -203,7 +203,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]