From: bdemsky Date: Mon, 8 Mar 2004 00:28:36 +0000 (+0000) Subject: Added support for stack allocation. Check for NULL before calling memory checker. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=repair.git;a=commitdiff_plain;h=0b318afaec69dfabbaf366bd49dc7fa66c7befbf Added support for stack allocation. Check for NULL before calling memory checker. --- diff --git a/Repair/RepairCompiler/MCC/IR/DotExpr.java b/Repair/RepairCompiler/MCC/IR/DotExpr.java index 7924bb4..38ee61a 100755 --- a/Repair/RepairCompiler/MCC/IR/DotExpr.java +++ b/Repair/RepairCompiler/MCC/IR/DotExpr.java @@ -168,16 +168,18 @@ public class DotExpr extends Expr { /* type var = [*(int *)] (base + offset) */ writer.outputline("int " + dest.getSafeSymbol()+"=0;"); writer.outputline("if ("+leftd.getSafeSymbol()+")"); + writer.startblock(); writer.outputline(dest.getSafeSymbol() + " = " + ptr + "(" + leftd.getSafeSymbol() + " + " + offset + ");"); - writer.outputline("else maybe=1;"); if (fd.getPtr()) { + writer.outputline("if ("+dest.getSafeSymbol()+")"); + writer.startblock(); VarDescriptor typevar=VarDescriptor.makeNew("typechecks"); if (DOMEMCHECKS&&(!DOTYPECHECKS)) { - writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidmemory(" + dest.getSafeSymbol() + ", " + td.getId() + ");"); + writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidmemory(" + dest.getSafeSymbol() + ", " + this.td.getId() + ");"); dotypecheck = true; } else if (DOTYPECHECKS) { - writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidtype(" + dest.getSafeSymbol() + ", " + td.getId() + ");"); + writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidtype(" + dest.getSafeSymbol() + ", " + this.td.getId() + ");"); } writer.outputline("if (!"+typevar.getSafeSymbol()+")"); writer.startblock(); @@ -185,7 +187,10 @@ public class DotExpr extends Expr { if (DONULL) writer.outputline(ptr + "(" + leftd.getSafeSymbol() + " + " + offset + ")=0;"); writer.endblock(); + writer.endblock(); } + writer.endblock(); + writer.outputline("else maybe=1;"); } } else { /* offset in bits is an expression that must be generated */ VarDescriptor ob = VarDescriptor.makeNew("offsetinbits"); @@ -220,16 +225,18 @@ public class DotExpr extends Expr { /* type var = [*(int *)] (base + offset) */ writer.outputline("int " + dest.getSafeSymbol() +"=0;"); writer.outputline("if ("+leftd.getSafeSymbol()+")"); + writer.startblock(); writer.outputline(dest.getSafeSymbol() + " = " + ptr + "(" + leftd.getSafeSymbol() + " + " + offset.getSafeSymbol() + ");"); - writer.outputline("else maybe=1;"); if (fd.getPtr()) { + writer.outputline("if ("+dest.getSafeSymbol()+")"); + writer.startblock(); VarDescriptor typevar=VarDescriptor.makeNew("typechecks"); if (DOMEMCHECKS&&(!DOTYPECHECKS)) { - writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidmemory(" + dest.getSafeSymbol() + ", " + td.getId() + ");"); + writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidmemory(" + dest.getSafeSymbol() + ", " + this.td.getId() + ");"); dotypecheck = true; } else if (DOTYPECHECKS) { - writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidtype(" + dest.getSafeSymbol() + ", " + td.getId() + ");"); + writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidtype(" + dest.getSafeSymbol() + ", " + this.td.getId() + ");"); } writer.outputline("if (!"+typevar.getSafeSymbol()+")"); writer.startblock(); @@ -237,7 +244,10 @@ public class DotExpr extends Expr { if (DONULL) writer.outputline(ptr + "(" + leftd.getSafeSymbol() + " + " + offset.getSafeSymbol() + ")=0;"); writer.endblock(); + writer.endblock(); } + writer.endblock(); + writer.outputline("else maybe=1;"); } } } diff --git a/Repair/RepairCompiler/MCC/IR/RepairGenerator.java b/Repair/RepairCompiler/MCC/IR/RepairGenerator.java index 82af1ba..52631d4 100755 --- a/Repair/RepairCompiler/MCC/IR/RepairGenerator.java +++ b/Repair/RepairCompiler/MCC/IR/RepairGenerator.java @@ -410,6 +410,8 @@ public class RepairGenerator { crhead.outputline("void doanalysis();"); craux.outputline("void "+name +"_state::doanalysis()"); craux.startblock(); + craux.outputline("int highmark;"); + craux.outputline("initializestack(&highmark);"); craux.outputline("typeobject *typeobject1=gettypeobject();"); craux.outputline("typeobject1->computesizes(this);"); craux.outputline("recomputesizes();"); diff --git a/Repair/RepairCompiler/MCC/IR/StructureGenerator.java b/Repair/RepairCompiler/MCC/IR/StructureGenerator.java index fe8e4b1..e9a94fb 100755 --- a/Repair/RepairCompiler/MCC/IR/StructureGenerator.java +++ b/Repair/RepairCompiler/MCC/IR/StructureGenerator.java @@ -42,6 +42,7 @@ public class StructureGenerator { private void generatecalls() { int max=TypeDescriptor.counter; cr.outputline("int arsize["+max+"];"); + cr.outputline("int arsizeBytes["+max+"];"); for(int i=0;icomputesizes(arsize,arnumelements);"); + cr.outputline("for(int i=0;i<"+max+";i++) {"); + cr.outputline("int bits=arsize[i];"); + cr.outputline("int bytes=bits>>3;"); + cr.outputline("if (bits%8) bytes++;"); + cr.outputline("arsizeBytes[i]=bytes;"); + cr.outputline("}"); cr.outputline("}"); } @@ -95,6 +106,7 @@ public class StructureGenerator { crhead.outputline("int isPtr(int type, int fieldindex);"); crhead.outputline("int numElements(int type, int fieldindex);"); crhead.outputline("int size(int type);"); + crhead.outputline("int sizeBytes(int type);"); crhead.outputline("int getnumfields(int type);"); crhead.outputline("bool issubtype(int subtype, int type);"); crhead.outputline("void computesizes("+rg.name+"_state *);"); diff --git a/Repair/RepairCompiler/MCC/IR/VarExpr.java b/Repair/RepairCompiler/MCC/IR/VarExpr.java index 2a71140..51e916a 100755 --- a/Repair/RepairCompiler/MCC/IR/VarExpr.java +++ b/Repair/RepairCompiler/MCC/IR/VarExpr.java @@ -83,6 +83,8 @@ public class VarExpr extends Expr { " = (" + vd.getType().getGenerateType().getSafeSymbol() + ") " + vd.getSafeSymbol() + "; //varexpr"); if (vd.isGlobal() && (DOTYPECHECKS||DOMEMCHECKS) && (td instanceof StructureTypeDescriptor)) { VarDescriptor typevar=VarDescriptor.makeNew("typechecks"); + writer.outputline("if ("+dest.getSafeSymbol()+")"); + writer.startblock(); if (DOTYPECHECKS) writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidtype(" + dest.getSafeSymbol() + ", " + td.getId() + ");"); else @@ -93,6 +95,7 @@ public class VarExpr extends Expr { if (DONULL) writer.outputline(vd.getSafeSymbol()+"=0;"); writer.endblock(); + writer.endblock(); } }