fix Issue 12044 - Invalid code gen causes segfault

fix https://d.puremagic.com/issues/show_bug.cgi?id=12044