Bugzilla – Bug 87
llvm-gcc infinite loops on "case MAXINT:"
Last modified: 2003-11-04 13:58:44
You need to log in before you can comment on or make changes to this bug.
Test case, reduced from linux-2.4.22/kernel/sched.c: struct list_head { struct list_head *next, *prev; }; void __list_add(struct list_head *new, struct list_head *prev, struct list_head *next) { next->prev = new; new->next = next; new->prev = prev; prev->next = new; } signed long schedule_timeout(signed long timeout) { switch (timeout) { case ((long)(~0UL>>1)): default: ; } return timeout < 0 ? 0 : timeout; }
I've also managed to get crashes or out of memory using an even shorter snippet of code: void schedule_timeout(signed long timeout) { switch (timeout) { case ((long)(~0UL>>1)): break; } }
This is now fixed. Testcase: test/Regression/CFrontend/2003-11-04-OutOfMemory.c Here's a CFE patch: $ diff -u llvm-expand.c~ llvm-expand.c --- llvm-expand.c~ 2003-11-03 23:49:27.000000000 -0600 +++ llvm-expand.c 2003-11-04 12:31:40.000000000 -0600 @@ -1738,7 +1738,7 @@ Low = (int)TREE_INT_CST_LOW(low); High = (int)TREE_INT_CST_LOW(high); - for (; Low <= High; ++Low) { + for (; Low != High+1; ++Low) { llvm_switch_case *NewCase = xmalloc(sizeof(llvm_switch_case)); NewCase->Next = SwitchInst->x.Switch.Cases; SwitchInst->x.Switch.Cases = NewCase;