Make stack checks in compiler more reliable, add more test cases