[vala/wip/issue/838: 2/6] codegen: Inline allocated arrays don't require checking for null
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/issue/838: 2/6] codegen: Inline allocated arrays don't require checking for null
- Date: Fri, 30 Aug 2019 14:14:37 +0000 (UTC)
commit 16b237af8b2d0185c587748190544cde9197300d
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Thu Aug 29 10:29:29 2019 +0200
codegen: Inline allocated arrays don't require checking for null
Found by -Werror=unreachable-code
codegen/valaccodearraymodule.vala | 10 +++++-----
codegen/valaccodeassignmentmodule.vala | 2 +-
codegen/valaccodebasemodule.vala | 13 ++++++++++---
codegen/valaccodecontrolflowmodule.vala | 2 +-
codegen/valaccodemethodcallmodule.vala | 2 +-
codegen/valaccodestructmodule.vala | 2 +-
codegen/valagasyncmodule.vala | 4 ++--
7 files changed, 21 insertions(+), 14 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 07a9a5399..bfe3ccaa4 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -419,7 +419,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
cfile.add_function (fun);
}
- public override TargetValue? copy_value (TargetValue value, CodeNode node) {
+ public override TargetValue? copy_value (TargetValue value, DataType? src_type, CodeNode node) {
var type = value.value_type;
var cexpr = get_cvalue_ (value);
@@ -427,7 +427,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
var array_type = (ArrayType) type;
if (!array_type.fixed_length) {
- return base.copy_value (value, node);
+ return base.copy_value (value, src_type, node);
}
var temp_value = create_temp_value (type, false, node);
@@ -439,7 +439,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
return temp_value;
} else {
- return base.copy_value (value, node);
+ return base.copy_value (value, src_type, node);
}
}
@@ -528,7 +528,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
new CCodeBinaryExpression (CCodeBinaryOperator.LESS_THAN, new
CCodeIdentifier ("i"), new CCodeIdentifier ("length")),
new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT,
new CCodeIdentifier ("i")));
- ccode.add_assignment (new CCodeElementAccess (new CCodeIdentifier ("result"), new
CCodeIdentifier ("i")), get_cvalue_ (copy_value (new GLibValue (array_type.element_type, new
CCodeElementAccess (new CCodeIdentifier ("self"), new CCodeIdentifier ("i")), true), array_type)));
+ ccode.add_assignment (new CCodeElementAccess (new CCodeIdentifier ("result"), new
CCodeIdentifier ("i")), get_cvalue_ (copy_value (new GLibValue (array_type.element_type, new
CCodeElementAccess (new CCodeIdentifier ("self"), new CCodeIdentifier ("i")), true), array_type,
array_type)));
ccode.close ();
ccode.add_return (new CCodeIdentifier ("result"));
@@ -582,7 +582,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT,
new CCodeIdentifier ("i")));
- ccode.add_assignment (new CCodeElementAccess (new CCodeIdentifier ("dest"), new
CCodeIdentifier ("i")), get_cvalue_ (copy_value (new GLibValue (array_type.element_type, new
CCodeElementAccess (new CCodeIdentifier ("self"), new CCodeIdentifier ("i")), true), array_type)));
+ ccode.add_assignment (new CCodeElementAccess (new CCodeIdentifier ("dest"), new
CCodeIdentifier ("i")), get_cvalue_ (copy_value (new GLibValue (array_type.element_type, new
CCodeElementAccess (new CCodeIdentifier ("self"), new CCodeIdentifier ("i")), true), array_type,
array_type)));
} else {
cfile.add_include ("string.h");
diff --git a/codegen/valaccodeassignmentmodule.vala b/codegen/valaccodeassignmentmodule.vala
index 617293b0a..43f62b4a0 100644
--- a/codegen/valaccodeassignmentmodule.vala
+++ b/codegen/valaccodeassignmentmodule.vala
@@ -210,7 +210,7 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
if (requires_copy (param_type) && !capturing_parameter_in_coroutine) {
// do not copy value when capturing parameter in coroutine
// as the value was already copied on coroutine initialization
- value = copy_value (value, param);
+ value = copy_value (value, param_type, param);
}
if (old_coroutine) {
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 1e2b4b38e..8c6a2ba57 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4365,7 +4365,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return true;
}
- public virtual TargetValue? copy_value (TargetValue value, CodeNode node) {
+ public virtual TargetValue? copy_value (TargetValue value, DataType? src_type, CodeNode node) {
var type = value.value_type;
var cexpr = get_cvalue_ (value);
var result = ((GLibValue) value).copy ();
@@ -4531,6 +4531,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
ccode.open_if (cnotnull);
ccode.add_expression (ccall);
ccode.close ();
+ } else if (src_type is ArrayType && ((ArrayType) src_type).inline_allocated) {
+ // inline allocated arrays can't be null
+ result.cvalue = ccall;
+ result = (GLibValue) store_temp_value (result, node, true);
} else {
var ccond = new CCodeConditionalExpression (cnotnull, ccall, cifnull);
result.cvalue = ccond;
@@ -6087,11 +6091,14 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (target_array.element_type.value_owned && !array.element_type.value_owned) {
array_needs_copy = requires_copy (target_array.element_type);
}
+ if (node is CastExpression && ((CastExpression) node).inner.target_type is ArrayType)
{
+ type = ((CastExpression) node).inner.target_type;
+ }
}
if (!gvalue_boxing && !gvariant_boxing && target_type.value_owned && (!type.value_owned ||
boxing || unboxing || array_needs_copy) && requires_copy (target_type) && !(type is NullType)) {
// need to copy value
- var copy = (GLibValue) copy_value (result, node);
+ var copy = (GLibValue) copy_value (result, type, node);
if (target_type.data_type is Interface && copy == null) {
Report.error (node.source_reference, "missing class prerequisite for
interface `%s', add GLib.Object to interface declaration if unsure".printf
(target_type.data_type.get_full_name ()));
return result;
@@ -6473,7 +6480,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (f.binding == MemberBinding.INSTANCE) {
var value = load_field (f, load_this_parameter ((TypeSymbol) st));
if ((!(f.variable_type is DelegateType) || get_ccode_delegate_target (f)) &&
requires_copy (f.variable_type)) {
- value = copy_value (value, f);
+ value = copy_value (value, f.variable_type, f);
if (value == null) {
// error case, continue to avoid critical
continue;
diff --git a/codegen/valaccodecontrolflowmodule.vala b/codegen/valaccodecontrolflowmodule.vala
index df31fcef3..94ce70670 100644
--- a/codegen/valaccodecontrolflowmodule.vala
+++ b/codegen/valaccodecontrolflowmodule.vala
@@ -329,7 +329,7 @@ public abstract class Vala.CCodeControlFlowModule : CCodeMethodModule {
CCodeExpression element_expr = new CCodeUnaryExpression
(CCodeUnaryOperator.POINTER_INDIRECTION, get_item);
if (stmt.type_reference.value_owned) {
- element_expr = get_cvalue_ (copy_value (new GLibValue (stmt.type_reference,
element_expr), new StructValueType (gvalue_type)));
+ element_expr = get_cvalue_ (copy_value (new GLibValue (stmt.type_reference,
element_expr), new StructValueType (gvalue_type), new StructValueType (gvalue_type)));
}
visit_local_variable (stmt.element_variable);
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 4e5cb10b8..92f949087 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -200,7 +200,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
} else if (m is ArrayMoveMethod) {
requires_array_move = true;
} else if (m is ArrayCopyMethod) {
- expr.target_value = copy_value (ma.inner.target_value, expr);
+ expr.target_value = copy_value (ma.inner.target_value, ma.inner.value_type, expr);
return;
}
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index 048cbb790..e523b9b17 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -307,7 +307,7 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
if (f.binding == MemberBinding.INSTANCE) {
var value = load_field (f, load_this_parameter ((TypeSymbol) st));
if ((!(f.variable_type is DelegateType) || get_ccode_delegate_target (f)) &&
requires_copy (f.variable_type)) {
- value = copy_value (value, f);
+ value = copy_value (value, f.variable_type, f);
if (value == null) {
// error case, continue to avoid critical
continue;
diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala
index 68a13dd29..4bceb003b 100644
--- a/codegen/valagasyncmodule.vala
+++ b/codegen/valagasyncmodule.vala
@@ -259,7 +259,7 @@ public class Vala.GAsyncModule : GtkModule {
cself = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION,
cself);
}
if (requires_copy (this_type)) {
- cself = get_cvalue_ (copy_value (new GLibValue
(m.this_parameter.variable_type, cself, true), m.this_parameter));
+ cself = get_cvalue_ (copy_value (new GLibValue
(m.this_parameter.variable_type, cself, true), this_type, m.this_parameter));
}
ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, "self"), cself);
@@ -592,7 +592,7 @@ public class Vala.GAsyncModule : GtkModule {
// structs are returned via out parameter
CCodeExpression cexpr = new CCodeMemberAccess.pointer (data_var, "result");
if (requires_copy (return_type)) {
- cexpr = get_cvalue_ (copy_value (new GLibValue (return_type, cexpr, true),
return_type));
+ cexpr = get_cvalue_ (copy_value (new GLibValue (return_type, cexpr, true),
return_type, return_type));
}
ccode.add_assignment (new CCodeUnaryExpression
(CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("result")), cexpr);
} else if (!(return_type is VoidType)) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]