Author: shihui
Date: 2011-05-06 02:01:17 -0400 (Fri, 06 May 2011)
New Revision: 3587

Modified:
   trunk/osprey/be/com/constraint_graph.cxx
Log:
Fix bug764:

ConstraintGraph::handleAlloca(WN *stmt)  assume stmt
assign allocated result direclty to a pointer type symbol, otherwise allocated 
size is 0.

There two more cases not considered in this method.
1. statement can be STID or ISTORE to a struct's field, this field is a pointer.
2. allocated result is converted and stored to long long integer.

Fix is
1. Extract field type as lhs type  when stmt has field id.
2. Allow LHS is not pointer but pointer mtype. In this case assume its void*.

Code review by Jianxin


Modified: trunk/osprey/be/com/constraint_graph.cxx
===================================================================
--- trunk/osprey/be/com/constraint_graph.cxx    2011-05-05 23:15:18 UTC (rev 
3586)
+++ trunk/osprey/be/com/constraint_graph.cxx    2011-05-06 06:01:17 UTC (rev 
3587)
@@ -79,6 +79,17 @@
   return 0;
 }
 
+static TY_IDX
+get_field_type (TY_IDX struct_type, UINT field_id)
+{
+  Is_True (TY_kind (struct_type) == KIND_STRUCT, ("expecting KIND_STRUCT"));
+  UINT cur_field_id = 0;
+  FLD_HANDLE fld = FLD_get_to_field (struct_type, field_id, cur_field_id);
+  Is_True (! fld.Is_Null(), ("Invalid field id %d for type 0x%x",
+                            field_id, struct_type));
+  return FLD_type (fld);
+}
+
 void
 ConstraintGraph::remapDeletedNode(WN *wn)
 {
@@ -1514,8 +1525,13 @@
   WN *rhs = WN_kid0(stmt);
   FmtAssert(WN_operator(rhs) == OPR_ALLOCA, ("Expecting alloca as kid 0"));
   // Handle ALLOCA which must appear as the rhs of a store 
-  TY &stack_ptr_ty = Ty_Table[WN_ty(stmt)];
-  if (TY_kind(stack_ptr_ty) != KIND_POINTER) {
+  TY_IDX ty_idx = WN_ty(stmt);
+  if (TY_kind(ty_idx) == KIND_STRUCT) {
+    ty_idx = get_field_type(ty_idx, WN_field_id(stmt));
+  }
+  TY &stack_ptr_ty = Ty_Table[ty_idx];
+  if (TY_kind(stack_ptr_ty) != KIND_POINTER &&
+      TY_mtype(stack_ptr_ty) != Pointer_Mtype) {
     // May be looking at an ALLOCA with size 0, in which
     // case we will simply skip this RHS.  These can result
     // when lowering INTRN_F90_STACKTEMPALLOC for example.
@@ -1526,7 +1542,14 @@
                   "0 byte allocation\n"));
     return ConstraintGraph::notAPointer();
   } else {
-    TY_IDX stack_ty_idx = TY_pointed(stack_ptr_ty);
+    TY_IDX stack_ty_idx;
+    if (TY_kind(stack_ptr_ty) != KIND_POINTER) {
+      // don't know pointer type, assume char *
+      stack_ty_idx = MTYPE_To_TY(MTYPE_I1);
+    }
+    else {
+      stack_ty_idx = TY_pointed(stack_ptr_ty);
+    }
     // We create a local variable that represents the dynamically
     // allocated stack location.
     // Create a symbol based in the pointed to type


------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Open64-devel mailing list
Open64-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/open64-devel

Reply via email to