EXC_BAD_ACCESS: invalid MemoryBuffer from ContentCache::getBuffer

I'm using the latest llvm/clang 2.8 releases and am getting
EXC_BAD_ACCESS crashes in ContentCache::getBuffer. This happens when
I'm printing out errors from a compilation run and iterating over
TextDiagnosticBuffer returned errors.

When checking the errors, I construct a FullSourceLoc and do:

int LineNum = SourceLoc.getInstantiationLineNumber();
int ColNum = SourceLoc.getInstantiationColumnNumber();

which return sane values. Checking SourceLoc.isInvalid() always
returns false, so I'm confident SourceLoc is valid. However, when I
do:

const char * bufname = SourceLoc.getManager().getBufferName(SourceLoc,
&invalid);

I get crashes. The different here I noticed is that
SourceLoc.getInstantiationColumnNumber() uses
getDecomposedInstantiationLoc(Loc) to grab the FileID while getBuffer
name uses getFileID(Loc), which in the case of the crash return
different values for FileID.

First, is the way I'm attempting to get the name of the source
location valid? Or, is there something I should be checking related
to the SourceLoc so that this crash doesn't happen? I guess I'm
wondering if getBufferName as any assumptions about SourceLoc that I
should know about.

thanks,
wes

I would just like to add some example code that generates this
behavior. There's a dangling long comment token that creates the
errors. I've tried to remove more of the code, but couldn't get it
any smaller and till reproduce the crash.

#include <stdio.h>

template <typename T, unsigned N>
struct VecN{
public:
  T v[N];
  
  VecN() {}
  
  VecN(T *vv) {
    for(unsigned int i=0; i < N; i++) {
      v[i] = vv[i];
    }
  }
  
  VecN(const VecN &vn) {
    for(unsigned int i=0; i < N; i++) {
      v[i] = vn.v[i];
    }
  }

  /*! Addition */
  const VecN operator+ (const VecN &vn) const {
    VecN res;
    for(unsigned int i=0; i < N; i++) {
      res.v[i] = v[i]+vn.v[i];
    }
    return res;
  }
};

extern "C" {

/* out0 = 1.4*in0*in0+2; */
#define MAT(x) (*(x))

int test() {
  float data[12] = {0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11.};
  float out_data[12];
  
  */
  VecN<float, 6> *v_in = (VecN<float, 6> *)data;
  VecN<float, 6> *v_out = (VecN<float, 6> *)out_data;
  for(int i=0; i < 2; i++) {
    MAT(v_out) = MAT(v_in)+MAT(v_in);
    v_in++;
    v_out++;
  }

  return 0;
}