This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gccgo] Clear value if key not present in conditional map lookup


For v, ok = m[k], if k is not present in the map, the program should
clear v.  gccgo was not doing that.  I committed this patch to the
gccgo branch to fix that.

Ian

diff -r 9e2d51e4c5fc go/statements.cc
--- a/go/statements.cc	Sat Jan 30 11:34:32 2010 -0800
+++ b/go/statements.cc	Sat Jan 30 22:01:19 2010 -0800
@@ -986,14 +986,9 @@
   Statement* s = Statement::make_assignment(ref, call, loc);
   b->add_statement(s);
 
-  // if present_temp { val = val_temp }
-  Block* then_block = new Block(b, loc);
+  // val = val_temp
   ref = Expression::make_temporary_reference(val_temp, loc);
   s = Statement::make_assignment(this->val_, ref, loc);
-  then_block->add_statement(s);
-
-  ref = Expression::make_temporary_reference(present_temp, loc);
-  s = Statement::make_if_statement(ref, then_block, NULL, loc);
   b->add_statement(s);
 
   // present = present_temp
diff -r 9e2d51e4c5fc libgo/runtime/map.cgo
--- a/libgo/runtime/map.cgo	Sat Jan 30 11:34:32 2010 -0800
+++ b/libgo/runtime/map.cgo	Sat Jan 30 22:01:19 2010 -0800
@@ -19,10 +19,11 @@
 	size_t valsize;
 
 	mapval = __go_map_index(h, key, 0);
+	valsize = h->__descriptor->__map_descriptor->__val_type->__size;
 	if (mapval == nil) {
+		__builtin_memset(val, 0, valsize);
 		present = 0;
 	} else {
-		valsize = h->__descriptor->__map_descriptor->__val_type->__size;
 		__builtin_memcpy(val, mapval, valsize);
 		present = 1;
 	}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]