First Last Prev Next    No search results available
Details
: llvm-gcc infinite loops on "case MAXINT:"
Bug#: 87
: tools
: llvm-gcc
Status: RESOLVED
Resolution: FIXED
: PC
: Linux
: 1.0
: P2
: blocker
: 1.1

:
: compile-fail
:
:
  Show dependency tree - Show dependency graph
People
Reporter: Misha Brukman <brukman+bugs@uiuc.edu>
Assigned To: Chris Lattner <sabre@nondot.org>

Attachments


Note

You need to log in before you can comment on or make changes to this bug.

Related actions


Description:   Opened: 2003-11-04 12:22
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;
}
------- Comment #1 From Misha Brukman 2003-11-04 12:25:23 -------
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;
 }
}
------- Comment #2 From Chris Lattner 2003-11-04 12:34:39 -------
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;


First Last Prev Next    No search results available