[LLVMdev] EXC_BAD_ACCESS: invalid MemoryBuffer from ContentCache::getBuffer

Wesley Smith wesley.hoke at gmail.com
Wed Oct 13 07:47:05 PDT 2010


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;
}



More information about the llvm-dev mailing list