Program: 150110
Project: 150110
Buggy source:
/** 
 * Returns a common superclass of the two types. NOTE: If both types are references, but are not both loaded, then this may be a conservative approximation (java.lang.Object). If there is no common superclass, than null is returned.
 */
public static VM_TypeReference findCommonSuperclass(VM_TypeReference t1,VM_TypeReference t2){
  if (t1 == t2)   return t1;
  if (t1.isPrimitiveType() || t2.isPrimitiveType()) {
    if (t1.isIntLikeType() && t2.isIntLikeType()) {
      if (t1.isIntType() || t2.isIntType())       return VM_TypeReference.Int;
      if (t1.isCharType() || t2.isCharType())       return VM_TypeReference.Char;
      if (t1.isShortType() || t2.isShortType())       return VM_TypeReference.Short;
      if (t1.isByteType() || t2.isByteType())       return VM_TypeReference.Byte;
    }
 else     if (t1.isWordType() && t2.isWordType()) {
      return VM_TypeReference.Word;
    }
    return null;
  }
  if (t1 == VM_TypeReference.NULL_TYPE)   return t2;
  if (t2 == VM_TypeReference.NULL_TYPE)   return t1;
  if (OPT_IRGenOptions.DBG_TYPE)   VM.sysWrite("String_Node_Str" + t1 + "String_Node_Str"+ t2);
  int arrayDimensions=0;
  while (t1.isArrayType() && t2.isArrayType()) {
    ++arrayDimensions;
    t1=t1.getArrayElementType();
    t2=t2.getArrayElementType();
  }
  if (t1.isPrimitiveType() || t2.isPrimitiveType()) {
    VM_TypeReference type=VM_TypeReference.JavaLangObject;
    if (t1 == t2) {
      if (t1.isWordType()) {
        arrayDimensions++;
        type=t1;
      }
 else {
        if (VM.VerifyAssertions)         VM._assert(false);
      }
    }
    --arrayDimensions;
    while (arrayDimensions-- > 0)     type=type.getArrayTypeForElementType();
    if (OPT_IRGenOptions.DBG_TYPE)     VM.sysWrite("String_Node_Str" + type);
    return type;
  }
  if (!t1.isClassType() || !t2.isClassType()) {
    VM_TypeReference type=VM_TypeReference.JavaLangObject;
    while (arrayDimensions-- > 0)     type=type.getArrayTypeForElementType();
    if (OPT_IRGenOptions.DBG_TYPE)     VM.sysWrite("String_Node_Str" + type);
    return type;
  }
  VM_Class c1=(VM_Class)t1.peekResolvedType();
  VM_Class c2=(VM_Class)t2.peekResolvedType();
  if (c1 != null && c2 != null) {
    OPT_Stack s1=new OPT_Stack();
    do {
      s1.push(c1);
      c1=c1.getSuperClass();
    }
 while (c1 != null);
    OPT_Stack s2=new OPT_Stack();
    do {
      s2.push(c2);
      c2=c2.getSuperClass();
    }
 while (c2 != null);
    if (OPT_IRGenOptions.DBG_TYPE)     VM.sysWrite("String_Node_Str" + s1);
    if (OPT_IRGenOptions.DBG_TYPE)     VM.sysWrite("String_Node_Str" + s2);
    VM_TypeReference best=VM_TypeReference.JavaLangObject;
    while (!s1.empty() && !s2.empty()) {
      VM_Class temp=(VM_Class)s1.pop();
      if (temp == s2.pop())       best=temp.getTypeRef();
 else       break;
    }
    if (OPT_IRGenOptions.DBG_TYPE)     VM.sysWrite("String_Node_Str" + best);
    while (arrayDimensions-- > 0)     best=best.getArrayTypeForElementType();
    return best;
  }
 else {
    if (OPT_IRGenOptions.DBG_TYPE && c1 == null)     VM.sysWrite(c1 + "String_Node_Str");
    if (OPT_IRGenOptions.DBG_TYPE && c2 == null)     VM.sysWrite(c2 + "String_Node_Str");
    VM_TypeReference common=VM_TypeReference.JavaLangObject;
    while (arrayDimensions-- > 0)     common=common.getArrayTypeForElementType();
    return common;
  }
}

Fixed version (ground truth):
/** 
 * Returns a common superclass of the two types. NOTE: If both types are references, but are not both loaded, then this may be a conservative approximation (java.lang.Object). If there is no common superclass, than null is returned.
 */
public static VM_TypeReference findCommonSuperclass(VM_TypeReference t1,VM_TypeReference t2){
  if (t1 == t2)   return t1;
  if (t1.isPrimitiveType() || t2.isPrimitiveType()) {
    if (t1.isIntLikeType() && t2.isIntLikeType()) {
      if (t1.isIntType() || t2.isIntType())       return VM_TypeReference.Int;
      if (t1.isCharType() || t2.isCharType())       return VM_TypeReference.Char;
      if (t1.isShortType() || t2.isShortType())       return VM_TypeReference.Short;
      if (t1.isByteType() || t2.isByteType())       return VM_TypeReference.Byte;
    }
 else     if (t1.isWordType() && t2.isWordType()) {
      return VM_TypeReference.Word;
    }
    return null;
  }
  if (t1 == VM_TypeReference.NULL_TYPE)   return t2;
  if (t2 == VM_TypeReference.NULL_TYPE)   return t1;
  if (OPT_IRGenOptions.DBG_TYPE)   VM.sysWrite("String_Node_Str" + t1 + "String_Node_Str"+ t2);
  int arrayDimensions=0;
  while (t1.isArrayType() && t2.isArrayType()) {
    ++arrayDimensions;
    t1=t1.getArrayElementType();
    t2=t2.getArrayElementType();
  }
  if (t1.isPrimitiveType() || t2.isPrimitiveType()) {
    VM_TypeReference type=VM_TypeReference.JavaLangObject;
    if (t1 == t2) {
      if (t1.isWordType() && t2.isWordType()) {
        arrayDimensions++;
        type=t1;
      }
 else       if (t1.isCodeType() && t2.isCodeType()) {
        arrayDimensions++;
        type=t1;
      }
 else {
        if (VM.VerifyAssertions)         VM._assert(false);
      }
    }
    --arrayDimensions;
    while (arrayDimensions-- > 0)     type=type.getArrayTypeForElementType();
    if (OPT_IRGenOptions.DBG_TYPE)     VM.sysWrite("String_Node_Str" + type);
    return type;
  }
  if (!t1.isClassType() || !t2.isClassType()) {
    VM_TypeReference type=VM_TypeReference.JavaLangObject;
    while (arrayDimensions-- > 0)     type=type.getArrayTypeForElementType();
    if (OPT_IRGenOptions.DBG_TYPE)     VM.sysWrite("String_Node_Str" + type);
    return type;
  }
  VM_Class c1=(VM_Class)t1.peekResolvedType();
  VM_Class c2=(VM_Class)t2.peekResolvedType();
  if (c1 != null && c2 != null) {
    OPT_Stack s1=new OPT_Stack();
    do {
      s1.push(c1);
      c1=c1.getSuperClass();
    }
 while (c1 != null);
    OPT_Stack s2=new OPT_Stack();
    do {
      s2.push(c2);
      c2=c2.getSuperClass();
    }
 while (c2 != null);
    if (OPT_IRGenOptions.DBG_TYPE)     VM.sysWrite("String_Node_Str" + s1);
    if (OPT_IRGenOptions.DBG_TYPE)     VM.sysWrite("String_Node_Str" + s2);
    VM_TypeReference best=VM_TypeReference.JavaLangObject;
    while (!s1.empty() && !s2.empty()) {
      VM_Class temp=(VM_Class)s1.pop();
      if (temp == s2.pop())       best=temp.getTypeRef();
 else       break;
    }
    if (OPT_IRGenOptions.DBG_TYPE)     VM.sysWrite("String_Node_Str" + best);
    while (arrayDimensions-- > 0)     best=best.getArrayTypeForElementType();
    return best;
  }
 else {
    if (OPT_IRGenOptions.DBG_TYPE && c1 == null)     VM.sysWrite(c1 + "String_Node_Str");
    if (OPT_IRGenOptions.DBG_TYPE && c2 == null)     VM.sysWrite(c2 + "String_Node_Str");
    VM_TypeReference common=VM_TypeReference.JavaLangObject;
    while (arrayDimensions-- > 0)     common=common.getArrayTypeForElementType();
    return common;
  }
}