Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crude fixes to "potentially uninitialized variable" errors from clang #2

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ valgrind/herbgrind/Makefile: valgrind/README herbgrind/Makefile.am
# real makefile.
cd valgrind && ./autogen.sh
cd valgrind && \
CFLAGS="-fno-stack-protector" \
CFLAGS="-fno-stack-protector -O0" \
./configure --prefix=$(shell pwd)/valgrind/$(HG_LOCAL_INSTALL_NAME) \
--enable-only64bit \
--build=$(TARGET_PLAT)
Expand Down Expand Up @@ -113,7 +113,7 @@ deps/gmp-%/README: setup/gmp-$(GMP_VERSION).tar.xz setup/patch_gmp.sh
# locally instead of in a global location, so it doesn't conflict with
# other versions of gmp.
cd deps/gmp-$*/ && \
CFLAGS="-fno-stack-protector" \
CFLAGS="-fno-stack-protector -O0" \
ABI=$* \
./configure --prefix=$(shell pwd)/deps/gmp-$*/$(HG_LOCAL_INSTALL_NAME)
$(MAKE) -C deps/gmp-$*
Expand All @@ -130,7 +130,7 @@ MPFR_CONFIGURE_FLAGS = --disable-thread-safe

configure-mpfr-32:
cd deps/mpfr-32/ && \
CFLAGS="-fno-stack-protector" \
CFLAGS="-fno-stack-protector -O0" \
./configure --prefix=$(shell pwd)/deps/mpfr-32/$(HG_LOCAL_INSTALL_NAME) \
--with-gmp-build=$(shell pwd)/deps/gmp-32 \
--build=i386 \
Expand Down
4 changes: 2 additions & 2 deletions bench/tiny.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

int main(int argc, char** argv){
int x;
HERBGRIND_BEGIN();
/* HERBGRIND_BEGIN(); */
x = 1 + 2;
HERBGRIND_END();
/* HERBGRIND_END(); */
printf("x\n");
return 0;
}
58 changes: 57 additions & 1 deletion herbgrind/hg_instrument.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "include/hg_helper.h"
#include "include/hg_macros.h"
#include "runtime/hg_mathreplace.h"
#include "include/pub_tool_libcassert.h"

void instrumentStatement(IRStmt* st, IRSB* sbOut, Addr stAddr){
IRExpr* expr;
Expand Down Expand Up @@ -131,6 +132,7 @@ That doesn't seem flattened...\n");
// Here we'll instrument moving Shadow values into temps. See
// above.
addStmtToIRSB(sbOut, st);

if (!isFloat(sbOut->tyenv, st->Ist.WrTmp.tmp)) break;
expr = st->Ist.WrTmp.data;
switch(expr->tag) {
Expand All @@ -143,6 +145,7 @@ That doesn't seem flattened...\n");
mkU64(expr->Iex.Get.ty),
mkU64(st->Ist.WrTmp.tmp)));
addStmtToIRSB(sbOut, IRStmt_Dirty(copyShadowLocation));

break;
case Iex_GetI:
// See comments above on PutI to make sense of this thing.
Expand All @@ -158,6 +161,7 @@ That doesn't seem flattened...\n");
mkU64(expr->Iex.Get.ty),
mkU64(st->Ist.WrTmp.tmp)));
addStmtToIRSB(sbOut, IRStmt_Dirty(copyShadowLocation));

break;
case Iex_RdTmp:
copyShadowLocation =
Expand Down Expand Up @@ -202,6 +206,7 @@ That doesn't seem flattened...\n");
mkIRExprVec_2(mkU64(condTmp),
mkU64(st->Ist.WrTmp.tmp)));
addStmtToIRSB(sbOut, IRStmt_Dirty(copyShadowLocation));

}
break;
case Iex_Load:
Expand All @@ -214,6 +219,7 @@ That doesn't seem flattened...\n");
mkU64(expr->Iex.Load.ty),
mkU64(st->Ist.WrTmp.tmp)));
addStmtToIRSB(sbOut, IRStmt_Dirty(copyShadowLocation));

}
break;
case Iex_Qop:
Expand All @@ -239,6 +245,7 @@ That doesn't seem flattened...\n");
// Here we'll instrument moving Shadow values into memory,
// unconditionally.
addStmtToIRSB(sbOut, st);

expr = st->Ist.Store.data;
switch (expr->tag) {
case Iex_RdTmp:
Expand All @@ -250,6 +257,7 @@ That doesn't seem flattened...\n");
mkIRExprVec_2(mkU64(expr->Iex.RdTmp.tmp),
st->Ist.Store.addr));
addStmtToIRSB(sbOut, IRStmt_Dirty(copyShadowLocation));

}
break;
case Iex_Const:
Expand All @@ -266,34 +274,70 @@ That doesn't seem flattened...\n");
// Same as above, but only assigns the value to memory if a
// guard returns true.
addStmtToIRSB(sbOut, st);

// TEST TROUBLE HERE
// break;
//

expr = st->Ist.Store.data;

switch(expr->tag) {

case Iex_RdTmp:
/*

VG_(dmsg)("\
100\n");
VG_(exit)(100);

if (isFloat(sbOut->tyenv, expr->Iex.RdTmp.tmp)){

VG_(dmsg)("\
101\n");
VG_(exit)(101);
copyShadowLocation =
unsafeIRDirty_0_N(3,
"copyShadowTmptoMemG",
VG_(fnptr_to_fnentry)(&copyShadowTmptoMemG),
mkIRExprVec_3(st->Ist.StoreG.details->guard,
mkU64(expr->Iex.RdTmp.tmp),
st->Ist.StoreG.details->addr));
VG_(dmsg)("\
110\n");
VG_(exit)(110);
addStmtToIRSB(sbOut, IRStmt_Dirty(copyShadowLocation));

VG_(dmsg)("\
111\n");
VG_(exit)(111);
// TEST
break;
}
*/
break;
/*
case Iex_Const:
VG_(dmsg)("\
102\n");
VG_(exit)(102);
break;
*/
default:
// This shouldn't happen in flattened IR.
VG_(dmsg)("\
A non-constant or temp is being placed into memory in a single IR statement! \
That doesn't seem flattened...\n");
VG_(exit)(109);
break;
}
break;
case Ist_LoadG:
// Guarded load. This will load a value from memory, and write
// it to a temp, but only if a condition returns true.
addStmtToIRSB(sbOut, st);

// TEST
break;
if (isFloat(sbOut->tyenv, st->Ist.LoadG.details->dst)){
ALLOC(loadGInfo, "hg.loadGmalloc.1", 1, sizeof(LoadG_Info));
// These are the lines we'd like to write. Unfortunately, we
Expand All @@ -308,7 +352,7 @@ That doesn't seem flattened...\n");
addStmtToIRSB(sbOut, IRStmt_Store(ENDIAN, mkU64((uintptr_t)&(loadGInfo->cond)),
st->Ist.LoadG.details->guard));
addStmtToIRSB(sbOut, IRStmt_Store(ENDIAN, mkU64((uintptr_t)&(loadGInfo->src_mem)),
st->Ist.LoadG.details->addr));
st->Ist.LoadG.details->addr));
addStmtToIRSB(sbOut, IRStmt_Store(ENDIAN, mkU64((uintptr_t)&(loadGInfo->alt_tmp)),
st->Ist.LoadG.details->alt));
loadGInfo->dest_tmp = st->Ist.LoadG.details->dst;
Expand All @@ -320,6 +364,9 @@ That doesn't seem flattened...\n");
VG_(fnptr_to_fnentry)(&copyShadowMemtoTmpIf),
mkIRExprVec_1(mkU64((uintptr_t)loadGInfo)));
addStmtToIRSB(sbOut, IRStmt_Dirty(copyShadowLocation));

// TEST
break;
}
break;
case Ist_CAS:
Expand All @@ -332,6 +379,9 @@ That doesn't seem flattened...\n");
// TODO: Add something here if we ever want to support multithreading.

addStmtToIRSB(sbOut, st);

// TEST
break;
VG_(dmsg)("\
Warning! Herbgrind does not currently support the Compare and Swap instruction, \
because we don't support multithreaded programs.\n");
Expand All @@ -342,6 +392,9 @@ because we don't support multithreaded programs.\n");
// TODO: Add something here if we ever want to support multithreading.

addStmtToIRSB(sbOut, st);

// TEST
break;
VG_(dmsg)("\
Warning! Herbgrind does not currently support the Load Linked / Store Conditional \
set of instructions, because we don't support multithreaded programs.\n");
Expand All @@ -351,6 +404,9 @@ set of instructions, because we don't support multithreaded programs.\n");
// side effects should be denoted in the attributes of this
// instruction.
addStmtToIRSB(sbOut, st);

// TEST
break;
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions herbgrind/hg_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ IRSB* hg_instrument ( VgCallbackClosure* closure,
if (st->tag == Ist_IMark)
cur_addr = st->Ist.IMark.addr;
// Take a look at hg_instrument.c to see what's going on here.

instrumentStatement(st, sbOut, cur_addr);
}

Expand Down
6 changes: 3 additions & 3 deletions herbgrind/hg_mathwrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
// This macro is defined in include/hg_mathreplace_funcs.h, and
// invokes the above macro for each unary operation that needs to be
// wrapped.
WRAP_UNARY_OPS
/* WRAP_UNARY_OPS */

/*----------------------------
====== Binary Ops ============
Expand All @@ -84,7 +84,7 @@ WRAP_UNARY_OPS
// This macro is defined in include/hg_mathreplace_funcs.h, and
// invokes the above macro for each binary operation that needs to be
// wrapped.
WRAP_BINARY_OPS
/* WRAP_BINARY_OPS */

/*----------------------------
====== Ternary Ops ===========
Expand All @@ -105,4 +105,4 @@ WRAP_BINARY_OPS
// This macro is defined in include/hg_mathreplace_funcs.h, and
// invokes the above macro for each ternary operation that needs to be
// wrapped.
WRAP_TERNARY_OPS
/* WRAP_TERNARY_OPS */
2 changes: 1 addition & 1 deletion herbgrind/runtime/hg_mathreplace.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void performOp(OpType op, double* result, double* args){
// Get the actual value from the pointer they gave us.
mpfr_set_d(args_m[i], args[i], MPFR_RNDN);
// Get the location of the arg source slot in the op structure.
Op_Info** src_loc_slot;
Op_Info** src_loc_slot = NULL;
// Get the slot in the op info structure for the value source
// structure cooresponding to this argument.
switch(nargs){
Expand Down
5 changes: 5 additions & 0 deletions herbgrind/runtime/hg_shadowop.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include "../types/hg_ast.h"
#include "hg_runtime.h"

#include "../include/pub_tool_libcassert.h"

// Execute a shadow operation, storing the result of the high
// precision operation applied to the shadow value at the arg_tmp
// offset, into the shadow value at the dest_tmp offset. Depending on
Expand Down Expand Up @@ -827,6 +829,9 @@ VG_REGPARM(1) void executeBinaryShadowOp(Op_Info* opInfo){
opInfo->args.bargs.arg1_value,
&(opInfo->args.bargs.arg1_src));
argType = Lt_Floatx4;
} else {
/* impossible? */
tl_assert(0);
}

// Now we'll allocate memory for the shadowed result of this
Expand Down