[cfe-commits] [PATCH] Crash when constant folding switch statements (Bug 11656)

Aaron Ballman aaron at aaronballman.com
Sun Jan 15 15:36:53 PST 2012


Bug 11656 demonstrates a crash in the code generator on the following
(reduced) code:

int main(void){
	int x = 0;
	int i = 0;
	switch (4) {
		case 4: do {i++; x++; int x = 5; case 5: x++;} while (i < 3);
	}
	return x;
}

The crash happens because we omit the switch and case constructs
during constant folding, and simply perform the do loop.  However, the
do loop still has a case statement in it, but no enclosing switch
(that the CG recognizes).

I've attached a patch that should address this issue -- if there's no
enclosing switch instance available for a case statement, we generate
the sub statement without the accompanying case.

HTH!

~Aaron
-------------- next part --------------
A non-text attachment was scrubbed...
Name: switch_folding.patch
Type: application/octet-stream
Size: 794 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120115/40f9d45c/attachment.obj>


More information about the cfe-commits mailing list