Reviewers: danno, michael_dawson,

Description:
AIX: Fix 'may be used uninitialized' compiler errors

Fix additional cases where the AIX compiler reports that a variable
may be used uninitialized.

[email protected], [email protected]
BUG=

Please review this at https://codereview.chromium.org/1323313003/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+43, -43 lines):
  M src/heap/heap.cc
  M src/heap/heap-inl.h
  M src/heap/mark-compact.cc


Index: src/heap/heap-inl.h
diff --git a/src/heap/heap-inl.h b/src/heap/heap-inl.h
index 36e56a0aba75e8e8e50b558d549885210c23d028..9fbe3b520d613f1f876091901f2e2869c11fec2a 100644
--- a/src/heap/heap-inl.h
+++ b/src/heap/heap-inl.h
@@ -126,7 +126,7 @@ AllocationResult Heap::AllocateOneByteInternalizedString(
   AllocationSpace space = SelectSpace(size, TENURED);

   // Allocate string.
-  HeapObject* result;
+  HeapObject* result = nullptr;
   {
     AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE);
     if (!allocation.To(&result)) return allocation;
@@ -158,7 +158,7 @@ AllocationResult Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str,
   AllocationSpace space = SelectSpace(size, TENURED);

   // Allocate string.
-  HeapObject* result;
+  HeapObject* result = nullptr;
   {
     AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE);
     if (!allocation.To(&result)) return allocation;
@@ -206,7 +206,7 @@ AllocationResult Heap::AllocateRaw(int size_in_bytes, AllocationSpace space,
   isolate_->counters()->objs_since_last_young()->Increment();
 #endif

-  HeapObject* object;
+  HeapObject* object = nullptr;
   AllocationResult allocation;
   if (NEW_SPACE == space) {
     allocation = new_space_.AllocateRaw(size_in_bytes, alignment);
Index: src/heap/heap.cc
diff --git a/src/heap/heap.cc b/src/heap/heap.cc
index 3d8f4492027b93983fc55755c04904751bdcc4e1..46ed920ad1c8558f66f76ffeac8971887ed64aa0 100644
--- a/src/heap/heap.cc
+++ b/src/heap/heap.cc
@@ -1068,7 +1068,7 @@ bool Heap::ReserveSpace(Reservation* reservations) {
           } else {
             allocation = paged_space(space)->AllocateRawUnaligned(size);
           }
-          HeapObject* free_space;
+          HeapObject* free_space = nullptr;
           if (allocation.To(&free_space)) {
             // Mark with a free list node, in case we have a GC before
             // deserializing.
@@ -2583,7 +2583,7 @@ AllocationResult Heap::AllocatePartialMap(InstanceType instance_type,
 AllocationResult Heap::AllocateMap(InstanceType instance_type,
                                    int instance_size,
                                    ElementsKind elements_kind) {
-  HeapObject* result;
+  HeapObject* result = nullptr;
AllocationResult allocation = AllocateRaw(Map::kSize, MAP_SPACE, MAP_SPACE);
   if (!allocation.To(&result)) return allocation;

@@ -2622,7 +2622,7 @@ AllocationResult Heap::AllocateMap(InstanceType instance_type,

 AllocationResult Heap::AllocateFillerObject(int size, bool double_align,
                                             AllocationSpace space) {
-  HeapObject* obj;
+  HeapObject* obj = nullptr;
   {
AllocationAlignment align = double_align ? kDoubleAligned : kWordAligned;
     AllocationResult allocation = AllocateRaw(size, space, space, align);
@@ -2666,7 +2666,7 @@ const Heap::StructTable Heap::struct_table[] = {


 bool Heap::CreateInitialMaps() {
-  HeapObject* obj;
+  HeapObject* obj = nullptr;
   {
     AllocationResult allocation = AllocatePartialMap(MAP_TYPE, Map::kSize);
     if (!allocation.To(&obj)) return false;
@@ -2902,7 +2902,7 @@ bool Heap::CreateInitialMaps() {
       if (!AllocateByteArray(0, TENURED).To(&byte_array)) return false;
       set_empty_byte_array(byte_array);

-      BytecodeArray* bytecode_array;
+      BytecodeArray* bytecode_array = nullptr;
       AllocationResult allocation =
           AllocateBytecodeArray(0, nullptr, 0, 0, empty_fixed_array());
       if (!allocation.To(&bytecode_array)) {
@@ -2936,7 +2936,7 @@ AllocationResult Heap::AllocateHeapNumber(double value, MutableMode mode,

   AllocationSpace space = SelectSpace(size, pretenure);

-  HeapObject* result;
+  HeapObject* result = nullptr;
   {
     AllocationResult allocation =
         AllocateRaw(size, space, OLD_SPACE, kDoubleUnaligned);
@@ -2957,7 +2957,7 @@ AllocationResult Heap::AllocateHeapNumber(double value, MutableMode mode,
                                                                           \
     AllocationSpace space = SelectSpace(size, pretenure);                 \
                                                                           \
-    HeapObject* result;                                                   \
+    HeapObject* result = nullptr;                                         \
     {                                                                     \
       AllocationResult allocation =                                       \
           AllocateRaw(size, space, OLD_SPACE, kSimd128Unaligned);         \
@@ -2979,7 +2979,7 @@ AllocationResult Heap::AllocateCell(Object* value) {
   int size = Cell::kSize;
   STATIC_ASSERT(Cell::kSize <= Page::kMaxRegularHeapObjectSize);

-  HeapObject* result;
+  HeapObject* result = nullptr;
   {
     AllocationResult allocation = AllocateRaw(size, OLD_SPACE, OLD_SPACE);
     if (!allocation.To(&result)) return allocation;
@@ -2994,7 +2994,7 @@ AllocationResult Heap::AllocatePropertyCell() {
   int size = PropertyCell::kSize;
   STATIC_ASSERT(PropertyCell::kSize <= Page::kMaxRegularHeapObjectSize);

-  HeapObject* result;
+  HeapObject* result = nullptr;
   AllocationResult allocation = AllocateRaw(size, OLD_SPACE, OLD_SPACE);
   if (!allocation.To(&result)) return allocation;

@@ -3011,7 +3011,7 @@ AllocationResult Heap::AllocatePropertyCell() {
 AllocationResult Heap::AllocateWeakCell(HeapObject* value) {
   int size = WeakCell::kSize;
   STATIC_ASSERT(WeakCell::kSize <= Page::kMaxRegularHeapObjectSize);
-  HeapObject* result = NULL;
+  HeapObject* result = nullptr;
   {
     AllocationResult allocation = AllocateRaw(size, OLD_SPACE, OLD_SPACE);
     if (!allocation.To(&result)) return allocation;
@@ -3480,7 +3480,7 @@ AllocationResult Heap::AllocateForeign(Address address, // Statically ensure that it is safe to allocate foreigns in paged spaces.
   STATIC_ASSERT(Foreign::kSize <= Page::kMaxRegularHeapObjectSize);
   AllocationSpace space = (pretenure == TENURED) ? OLD_SPACE : NEW_SPACE;
-  Foreign* result;
+  Foreign* result = nullptr;
   AllocationResult allocation = Allocate(foreign_map(), space);
   if (!allocation.To(&result)) return allocation;
   result->set_foreign_address(address);
@@ -3494,7 +3494,7 @@ AllocationResult Heap::AllocateByteArray(int length, PretenureFlag pretenure) {
   }
   int size = ByteArray::SizeFor(length);
   AllocationSpace space = SelectSpace(size, pretenure);
-  HeapObject* result;
+  HeapObject* result = nullptr;
   {
     AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE);
     if (!allocation.To(&result)) return allocation;
@@ -3518,7 +3518,7 @@ AllocationResult Heap::AllocateBytecodeArray(int length,
   DCHECK(!InNewSpace(constant_pool));

   int size = BytecodeArray::SizeFor(length);
-  HeapObject* result;
+  HeapObject* result = nullptr;
   {
     AllocationResult allocation = AllocateRaw(size, OLD_SPACE, OLD_SPACE);
     if (!allocation.To(&result)) return allocation;
@@ -3705,7 +3705,7 @@ AllocationResult Heap::AllocateFixedTypedArrayWithExternalPointer(
     PretenureFlag pretenure) {
   int size = FixedTypedArrayBase::kHeaderSize;
   AllocationSpace space = SelectSpace(size, pretenure);
-  HeapObject* result;
+  HeapObject* result = nullptr;
   {
     AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE);
     if (!allocation.To(&result)) return allocation;
@@ -3750,7 +3750,7 @@ AllocationResult Heap::AllocateFixedTypedArray(int length,
                                   FixedTypedArrayBase::kDataOffset);
   AllocationSpace space = SelectSpace(size, pretenure);

-  HeapObject* object;
+  HeapObject* object = nullptr;
   AllocationResult allocation = AllocateRaw(
       size, space, OLD_SPACE,
       array_type == kExternalFloat64Array ? kDoubleAligned : kWordAligned);
@@ -3773,7 +3773,7 @@ AllocationResult Heap::AllocateCode(int object_size, bool immovable) {
   AllocationResult allocation =
       AllocateRaw(object_size, CODE_SPACE, CODE_SPACE);

-  HeapObject* result;
+  HeapObject* result = nullptr;
   if (!allocation.To(&result)) return allocation;

   if (immovable) {
@@ -3807,7 +3807,7 @@ AllocationResult Heap::AllocateCode(int object_size, bool immovable) {
 AllocationResult Heap::CopyCode(Code* code) {
   AllocationResult allocation;

-  HeapObject* result = NULL;
+  HeapObject* result = nullptr;
   // Allocate an object the same size as the code object.
   int obj_size = code->Size();
   allocation = AllocateRaw(obj_size, CODE_SPACE, CODE_SPACE);
@@ -3832,7 +3832,7 @@ AllocationResult Heap::CopyCode(Code* code) {
 AllocationResult Heap::CopyCode(Code* code, Vector<byte> reloc_info) {
   // Allocate ByteArray before the Code object, so that we do not risk
   // leaving uninitialized Code object (and breaking the heap).
-  ByteArray* reloc_info_array;
+  ByteArray* reloc_info_array = nullptr;
   {
     AllocationResult allocation =
         AllocateByteArray(reloc_info.length(), TENURED);
@@ -3848,7 +3848,7 @@ AllocationResult Heap::CopyCode(Code* code, Vector<byte> reloc_info) {
   size_t relocation_offset =
       static_cast<size_t>(code->instruction_end() - old_addr);

-  HeapObject* result;
+  HeapObject* result = nullptr;
   AllocationResult allocation =
       AllocateRaw(new_obj_size, CODE_SPACE, CODE_SPACE);
   if (!allocation.To(&result)) return allocation;
@@ -3903,7 +3903,7 @@ AllocationResult Heap::Allocate(Map* map, AllocationSpace space,
   if (allocation_site != NULL) {
     size += AllocationMemento::kSize;
   }
-  HeapObject* result;
+  HeapObject* result = nullptr;
   AllocationResult allocation = AllocateRaw(size, space, retry_space);
   if (!allocation.To(&result)) return allocation;
// No need for write barrier since object is white and map is in old space.
@@ -3965,7 +3965,7 @@ AllocationResult Heap::AllocateJSObjectFromMap(
   // Allocate the JSObject.
   int size = map->instance_size();
   AllocationSpace space = SelectSpace(size, pretenure);
-  JSObject* js_obj;
+  JSObject* js_obj = nullptr;
   AllocationResult allocation = Allocate(map, space, allocation_site);
   if (!allocation.To(&js_obj)) return allocation;

@@ -3986,7 +3986,7 @@ AllocationResult Heap::AllocateJSObject(JSFunction* constructor,
       constructor->initial_map(), pretenure, allocation_site);
 #ifdef DEBUG
   // Make sure result is NOT a global object if valid.
-  HeapObject* obj;
+  HeapObject* obj = nullptr;
   DCHECK(!allocation.To(&obj) || !obj->IsGlobalObject());
 #endif
   return allocation;
@@ -4003,7 +4003,7 @@ AllocationResult Heap::CopyJSObject(JSObject* source, AllocationSite* site) {
         map->instance_type() == JS_ARRAY_TYPE);

   int object_size = map->instance_size();
-  HeapObject* clone;
+  HeapObject* clone = nullptr;

   DCHECK(site == NULL || AllocationSite::CanTrack(map->instance_type()));

@@ -4074,7 +4074,7 @@ AllocationResult Heap::CopyJSObject(JSObject* source, AllocationSite* site) {
   FixedArray* properties = FixedArray::cast(source->properties());
   // Update elements if necessary.
   if (elements->length() > 0) {
-    FixedArrayBase* elem;
+    FixedArrayBase* elem = nullptr;
     {
       AllocationResult allocation;
       if (elements->map() == fixed_cow_array_map()) {
@@ -4090,7 +4090,7 @@ AllocationResult Heap::CopyJSObject(JSObject* source, AllocationSite* site) {
   }
   // Update properties if necessary.
   if (properties->length() > 0) {
-    FixedArray* prop;
+    FixedArray* prop = nullptr;
     {
       AllocationResult allocation = CopyFixedArray(properties);
       if (!allocation.To(&prop)) return allocation;
@@ -4168,7 +4168,7 @@ AllocationResult Heap::AllocateInternalizedStringImpl(T t, int chars,
   AllocationSpace space = SelectSpace(size, TENURED);

   // Allocate string.
-  HeapObject* result;
+  HeapObject* result = nullptr;
   {
     AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE);
     if (!allocation.To(&result)) return allocation;
@@ -4210,7 +4210,7 @@ AllocationResult Heap::AllocateRawOneByteString(int length,
   DCHECK(size <= SeqOneByteString::kMaxSize);
   AllocationSpace space = SelectSpace(size, pretenure);

-  HeapObject* result;
+  HeapObject* result = nullptr;
   {
     AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE);
     if (!allocation.To(&result)) return allocation;
@@ -4234,7 +4234,7 @@ AllocationResult Heap::AllocateRawTwoByteString(int length,
   DCHECK(size <= SeqTwoByteString::kMaxSize);
   AllocationSpace space = SelectSpace(size, pretenure);

-  HeapObject* result;
+  HeapObject* result = nullptr;
   {
     AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE);
     if (!allocation.To(&result)) return allocation;
@@ -4251,7 +4251,7 @@ AllocationResult Heap::AllocateRawTwoByteString(int length,

 AllocationResult Heap::AllocateEmptyFixedArray() {
   int size = FixedArray::SizeFor(0);
-  HeapObject* result;
+  HeapObject* result = nullptr;
   {
     AllocationResult allocation = AllocateRaw(size, OLD_SPACE, OLD_SPACE);
     if (!allocation.To(&result)) return allocation;
@@ -4269,7 +4269,7 @@ AllocationResult Heap::CopyAndTenureFixedCOWArray(FixedArray* src) {
   }

   int len = src->length();
-  HeapObject* obj;
+  HeapObject* obj = nullptr;
   {
     AllocationResult allocation = AllocateRawFixedArray(len, TENURED);
     if (!allocation.To(&obj)) return allocation;
@@ -4302,7 +4302,7 @@ AllocationResult Heap::CopyFixedArrayAndGrow(FixedArray* src, int grow_by,
   int old_len = src->length();
   int new_len = old_len + grow_by;
   DCHECK(new_len >= old_len);
-  HeapObject* obj;
+  HeapObject* obj = nullptr;
   {
AllocationResult allocation = AllocateRawFixedArray(new_len, pretenure);
     if (!allocation.To(&obj)) return allocation;
@@ -4322,7 +4322,7 @@ AllocationResult Heap::CopyFixedArrayAndGrow(FixedArray* src, int grow_by,

 AllocationResult Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) {
   int len = src->length();
-  HeapObject* obj;
+  HeapObject* obj = nullptr;
   {
     AllocationResult allocation = AllocateRawFixedArray(len, NOT_TENURED);
     if (!allocation.To(&obj)) return allocation;
@@ -4348,7 +4348,7 @@ AllocationResult Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) {
 AllocationResult Heap::CopyFixedDoubleArrayWithMap(FixedDoubleArray* src,
                                                    Map* map) {
   int len = src->length();
-  HeapObject* obj;
+  HeapObject* obj = nullptr;
   {
AllocationResult allocation = AllocateRawFixedDoubleArray(len, NOT_TENURED);
     if (!allocation.To(&obj)) return allocation;
@@ -4403,7 +4403,7 @@ AllocationResult Heap::AllocateFixedArray(int length, PretenureFlag pretenure) {
 AllocationResult Heap::AllocateUninitializedFixedArray(int length) {
   if (length == 0) return empty_fixed_array();

-  HeapObject* obj;
+  HeapObject* obj = nullptr;
   {
AllocationResult allocation = AllocateRawFixedArray(length, NOT_TENURED);
     if (!allocation.To(&obj)) return allocation;
@@ -4419,7 +4419,7 @@ AllocationResult Heap::AllocateUninitializedFixedDoubleArray(
     int length, PretenureFlag pretenure) {
   if (length == 0) return empty_fixed_array();

-  HeapObject* elements;
+  HeapObject* elements = nullptr;
AllocationResult allocation = AllocateRawFixedDoubleArray(length, pretenure);
   if (!allocation.To(&elements)) return allocation;

@@ -4438,7 +4438,7 @@ AllocationResult Heap::AllocateRawFixedDoubleArray(int length,
   int size = FixedDoubleArray::SizeFor(length);
   AllocationSpace space = SelectSpace(size, pretenure);

-  HeapObject* object;
+  HeapObject* object = nullptr;
   {
     AllocationResult allocation =
         AllocateRaw(size, space, OLD_SPACE, kDoubleAligned);
@@ -4453,7 +4453,7 @@ AllocationResult Heap::AllocateSymbol() {
   // Statically ensure that it is safe to allocate symbols in paged spaces.
   STATIC_ASSERT(Symbol::kSize <= Page::kMaxRegularHeapObjectSize);

-  HeapObject* result = NULL;
+  HeapObject* result = nullptr;
   AllocationResult allocation =
       AllocateRaw(Symbol::kSize, OLD_SPACE, OLD_SPACE);
   if (!allocation.To(&result)) return allocation;
@@ -4494,7 +4494,7 @@ AllocationResult Heap::AllocateStruct(InstanceType type) {
   }
   int size = map->instance_size();
   AllocationSpace space = SelectSpace(size, TENURED);
-  Struct* result;
+  Struct* result = nullptr;
   {
     AllocationResult allocation = Allocate(map, space);
     if (!allocation.To(&result)) return allocation;
Index: src/heap/mark-compact.cc
diff --git a/src/heap/mark-compact.cc b/src/heap/mark-compact.cc
index 6159796b4ba234726acb15cb2dd3b92d77f9bb79..3416dd76cc4f1947333af5896b2c1d0e05cf1097 100644
--- a/src/heap/mark-compact.cc
+++ b/src/heap/mark-compact.cc
@@ -2941,7 +2941,7 @@ bool MarkCompactCollector::TryPromoteObject(HeapObject* object,

   OldSpace* old_space = heap()->old_space();

-  HeapObject* target;
+  HeapObject* target = nullptr;
   AllocationAlignment alignment = object->RequiredAlignment();
AllocationResult allocation = old_space->AllocateRaw(object_size, alignment);
   if (allocation.To(&target)) {
@@ -3193,7 +3193,7 @@ void MarkCompactCollector::EvacuateLiveObjectsFromPage(Page* p) {

       int size = object->Size();
       AllocationAlignment alignment = object->RequiredAlignment();
-      HeapObject* target_object;
+      HeapObject* target_object = nullptr;
       AllocationResult allocation = space->AllocateRaw(size, alignment);
       if (!allocation.To(&target_object)) {
// If allocation failed, use emergency memory and re-try allocation.


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to