On 08/06/2013 10:42 AM, Marek Polacek wrote:
Hm, actually, we can't easily fold the call to the sanitize function away, I'm afraid, if we want to do it for the 'case <something>' case. When we hit the DIV_EXPR in 'case 0 * (1 / 0)', the ubsan_instrument_division gets 1 as a first argument and 0 as a second argument, but due to fold_builds in the ubsan_instrument_division, we replace the case value with just the call to the __builtin___ubsan_handle_divrem_overflow.
Ah, and the call isn't folded away because it has side-effects.
I think, what we could do, is to tweak verify_constant like this: + /* This is to handle e.g. the goofy 'case 0 * (1 / 0)' case. */ + if (flag_sanitize & SANITIZE_UNDEFINED + && TREE_CODE (t) == CALL_EXPR + && is_ubsan_builtin (t)) + { + error ("undefined behavior occured"); + return *non_constant_p; + }
I think I'd rather handle ubsan builtins specially in dump_expr. Jason