http://llvm.org/bugs/show_bug.cgi?id=20020

            Bug ID: 20020
           Summary: miscompile at -O1 produces crashing program (postRA
                    scheduler?)
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

The following C test case is a reduced version of
test-suite/SingleSource/Benchmarks/BenchmarkGame/n-body.c.

This program is crashing on both Linux x86-64 and OS X using clang trunk (v3.5)
like so:
$ ./clang -fmath-errno -O1 nbody_reduced.c -march=atom -lm
$ ./a.out 
Segmentation fault (core dumped)

I am suspicious of postRA scheduling because after I enabled postRA scheduling
for another target (btver2) and rebuilt clang, the program began crashing on
that target too. I don't see a way to toggle postRA scheduling via command-line
flags, but if that's possible, it would be much easier to test.

Any suggestions on how to isolate this fault?

$ cat nbody_reduced.c 
#include <math.h>

struct planet {
  double x, y;
  double vx, vy;
  double mass;
};

void advance(int nbodies, struct planet * bodies, double dt)
{
  int i, j;
  for (i = 0; i < nbodies; i++) {
    struct planet * b = &(bodies[i]);
    for (j = i + 1; j < nbodies; j++) {
      struct planet * b2 = &(bodies[j]);
      double dx = b->x - b2->x;
      double dy = b->y - b2->y;
      double distance = sqrt(dx * dx + dy * dy);
      double mag = dt / (distance * distance * distance);
      b->vx -= dx * b2->mass * mag;
      b->vy -= dy * b2->mass * mag;
    }
  }
  for (i = 0; i < nbodies; i++) {
    struct planet * b = &(bodies[i]);
    b->x += b->vx;
    b->y += 0.01 * b->vy;
  }
}

int main()
{
  struct planet bodies;
  advance(1, &bodies, 0.01);
  return 0;
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to