Wed, 25 Feb 2009 10:53:14 -0800
6805427: adlc compiler may generate incorrect machnode emission code
Reviewed-by: kvn, twisti
src/share/vm/adlc/formssel.cpp | file | annotate | diff | comparison | revisions | |
src/share/vm/adlc/formssel.hpp | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/vm/adlc/formssel.cpp Tue Feb 24 09:53:20 2009 -0800 1.2 +++ b/src/share/vm/adlc/formssel.cpp Wed Feb 25 10:53:14 2009 -0800 1.3 @@ -1217,13 +1217,17 @@ 1.4 // Seach through operands to determine parameters unique positions. 1.5 void InstructForm::set_unique_opnds() { 1.6 uint* uniq_idx = NULL; 1.7 - uint nopnds = num_opnds(); 1.8 + int nopnds = num_opnds(); 1.9 uint num_uniq = nopnds; 1.10 - uint i; 1.11 + int i; 1.12 + _uniq_idx_length = 0; 1.13 if ( nopnds > 0 ) { 1.14 - // Allocate index array with reserve. 1.15 - uniq_idx = (uint*) malloc(sizeof(uint)*(nopnds + 2)); 1.16 - for( i = 0; i < nopnds+2; i++ ) { 1.17 + // Allocate index array. Worst case we're mapping from each 1.18 + // component back to an index and any DEF always goes at 0 so the 1.19 + // length of the array has to be the number of components + 1. 1.20 + _uniq_idx_length = _components.count() + 1; 1.21 + uniq_idx = (uint*) malloc(sizeof(uint)*(_uniq_idx_length)); 1.22 + for( i = 0; i < _uniq_idx_length; i++ ) { 1.23 uniq_idx[i] = i; 1.24 } 1.25 } 1.26 @@ -1238,8 +1242,8 @@ 1.27 _parameters.reset(); 1.28 while( (name = _parameters.iter()) != NULL ) { 1.29 count = 0; 1.30 - uint position = 0; 1.31 - uint uniq_position = 0; 1.32 + int position = 0; 1.33 + int uniq_position = 0; 1.34 _components.reset(); 1.35 Component *comp = NULL; 1.36 if( sets_result() ) { 1.37 @@ -1255,6 +1259,7 @@ 1.38 } 1.39 if( strcmp(name, comp->_name)==0 ) { 1.40 if( ++count > 1 ) { 1.41 + assert(position < _uniq_idx_length, "out of bounds"); 1.42 uniq_idx[position] = uniq_position; 1.43 has_dupl_use = true; 1.44 } else {
2.1 --- a/src/share/vm/adlc/formssel.hpp Tue Feb 24 09:53:20 2009 -0800 2.2 +++ b/src/share/vm/adlc/formssel.hpp Wed Feb 25 10:53:14 2009 -0800 2.3 @@ -101,6 +101,7 @@ 2.4 const char *_ins_pipe; // Instruction Scheduline description class 2.5 2.6 uint *_uniq_idx; // Indexes of unique operands 2.7 + int _uniq_idx_length; // Length of _uniq_idx array 2.8 uint _num_uniq; // Number of unique operands 2.9 ComponentList _components; // List of Components matches MachNode's 2.10 // operand structure 2.11 @@ -257,11 +258,13 @@ 2.12 void set_unique_opnds(); 2.13 uint num_unique_opnds() { return _num_uniq; } 2.14 uint unique_opnds_idx(int idx) { 2.15 - if( _uniq_idx != NULL && idx > 0 ) 2.16 + if( _uniq_idx != NULL && idx > 0 ) { 2.17 + assert(idx < _uniq_idx_length, "out of bounds"); 2.18 return _uniq_idx[idx]; 2.19 - else 2.20 + } else { 2.21 return idx; 2.22 - } 2.23 + } 2.24 + } 2.25 2.26 // Operands which are only KILLs aren't part of the input array and 2.27 // require special handling in some cases. Their position in this