Skip to content

Commit

Permalink
Improve the messages given for uninitialized variable reads
Browse files Browse the repository at this point in the history
  • Loading branch information
lgritz committed Jun 20, 2015
1 parent 3e4a5c4 commit bd24123
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/liboslexec/builtindecl.h
Expand Up @@ -210,7 +210,7 @@ DECL (osl_dict_value, "iXiXLX")
DECL (osl_raytype_name, "iXX")
DECL (osl_range_check, "iiiXXi")
DECL (osl_naninf_check, "xiXiXXiXiiX")
DECL (osl_uninit_check, "xLXXXiXiXiXXii")
DECL (osl_uninit_check, "xLXXXiXiXXiXiXii")
DECL (osl_get_attribute, "iXiXXiiXX")
DECL (osl_bind_interpolated_param, "iXXLiXiXiXi")
DECL (osl_get_texture_options, "XX");
Expand Down
4 changes: 3 additions & 1 deletion src/liboslexec/llvm_instance.cpp
Expand Up @@ -647,13 +647,15 @@ BackendLLVM::llvm_generate_debug_uninit (const Opcode &op)
ll.constant(group().name()),
ll.constant(layer()),
ll.constant(inst()->layername()),
ll.constant(inst()->shadername().c_str()),
ll.constant(int(&op - &inst()->ops()[0])),
ll.constant(op.opname()),
ll.constant(i),
ll.constant(sym.name()),
offset,
ncheck
};
ll.call_function ("osl_uninit_check", args, 13);
ll.call_function ("osl_uninit_check", args, 15);
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/liboslexec/shadingsys.cpp
Expand Up @@ -2913,7 +2913,8 @@ OSL_SHADEOP void
osl_uninit_check (long long typedesc_, void *vals_,
void *sg, const void *sourcefile, int sourceline,
const char *groupname, int layer, const char *layername,
int opnum, const char *opname,
const char *shadername,
int opnum, const char *opname, int argnum,
void *symbolname, int firstcheck, int nchecks)
{
TypeDesc typedesc = TYPEDESC(typedesc_);
Expand Down Expand Up @@ -2944,11 +2945,11 @@ osl_uninit_check (long long typedesc_, void *vals_,
}
}
if (uninit) {
ctx->error ("Detected possible use of uninitialized value in %s at %s:%d (group %s, layer %d %s, op %d '%s')",
USTR(symbolname), USTR(sourcefile), sourceline,
ctx->error ("Detected possible use of uninitialized value in %s %s at %s:%d (group %s, layer %d %s, shader %s, op %d '%s', arg %d)",
typedesc, USTR(symbolname), USTR(sourcefile), sourceline,
groupname ? groupname: "<unnamed group>",
layer, layername ? layername : "<unnamed layer>",
opnum, USTR(opname));
shadername, opnum, USTR(opname), argnum);
}
}

Expand Down
6 changes: 3 additions & 3 deletions testsuite/debug-uninit/ref/out-opt2.txt
@@ -1,7 +1,7 @@
Compiled test.osl -> test.oso
ERROR: Detected possible use of uninitialized value in i_uninit at test.osl:10 (group <unnamed group>, layer 0 , op 0 'assign')
ERROR: Detected possible use of uninitialized value in int i_uninit at test.osl:10 (group <unnamed group>, layer 0 , shader test, op 0 'assign', arg 1)

Output Cout to Cout.tif
ERROR: Detected possible use of uninitialized value in f_uninit at test.osl:10 (group <unnamed group>, layer 0 , op 1 'color')
ERROR: Detected possible use of uninitialized value in s_uninit at test.osl:11 (group <unnamed group>, layer 0 , op 2 'texture')
ERROR: Detected possible use of uninitialized value in float f_uninit at test.osl:10 (group <unnamed group>, layer 0 , shader test, op 1 'color', arg 1)
ERROR: Detected possible use of uninitialized value in string s_uninit at test.osl:11 (group <unnamed group>, layer 0 , shader test, op 2 'texture', arg 1)
ERROR: [RendererServices::texture] ImageInput::create() called with no filename
6 changes: 3 additions & 3 deletions testsuite/debug-uninit/ref/out.txt
@@ -1,7 +1,7 @@
Compiled test.osl -> test.oso
ERROR: Detected possible use of uninitialized value in i_uninit at test.osl:10 (group <unnamed group>, layer 0 , op 3 'assign')
ERROR: Detected possible use of uninitialized value in int i_uninit at test.osl:10 (group <unnamed group>, layer 0 , shader test, op 3 'assign', arg 1)

Output Cout to Cout.tif
ERROR: Detected possible use of uninitialized value in f_uninit at test.osl:10 (group <unnamed group>, layer 0 , op 4 'color')
ERROR: Detected possible use of uninitialized value in s_uninit at test.osl:11 (group <unnamed group>, layer 0 , op 5 'texture')
ERROR: Detected possible use of uninitialized value in float f_uninit at test.osl:10 (group <unnamed group>, layer 0 , shader test, op 4 'color', arg 1)
ERROR: Detected possible use of uninitialized value in string s_uninit at test.osl:11 (group <unnamed group>, layer 0 , shader test, op 5 'texture', arg 1)
ERROR: [RendererServices::texture] ImageInput::create() called with no filename

0 comments on commit bd24123

Please sign in to comment.