[vala/0.52] codegen: Access of inline allocated array is guaranteed to be non null
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.52] codegen: Access of inline allocated array is guaranteed to be non null
- Date: Thu, 17 Feb 2022 08:46:58 +0000 (UTC)
commit 0c280b5a5f49778cdf91e5dc5b56aca36d1f1481
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sun Jan 23 18:46:48 2022 +0100
codegen: Access of inline allocated array is guaranteed to be non null
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 | 1 +
codegen/valaccodebasemodule.vala | 11 +++++++++--
vala/valamemberaccess.vala | 3 +++
3 files changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 0a76c72cb..c7df733e3 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -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);
}
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 77eff5877..3c76e5c10 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -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) {
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 5f90a8449..a56b7cf78 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]