imageworks/OpenShadingLanguage — pull request #259 by lgritz (2013-06-04 00:54:59+00:00)
Title: Debugging mode: detect uninitialized values

New ShadingSystem attribute "debug_uninit" tries to detect use of uninitialized values at runtime, somewhat similar to "debug_nan" operation. The basic idea is that all temps and locals are pre-initialized to special values (NaN for floats, -INT_MAX for ints, "!!!uninitialized!!!" for strings). Before every op, it checks all variables that are about to be read for these values. It's not perfect -- you will get "false positive" results if you purposely assign those special values in your shader. But I'm willing to bet that's a rare and unadvised case.

This is very expensive and so is off by default. But it's a very handy way to zero in on exactly where you are using an uninialized value!

For consistency, also renamed "debugnan" to "debug_nan" (but retained the old name as a synonym for back compatibility).

Produces output like this:

ERROR: Detected possible use of uninitialized value in i_uninit at test.osl:10
ERROR: Detected possible use of uninitialized value in f_uninit at test.osl:10
ERROR: Detected possible use of uninitialized value in s_uninit at test.osl:11