[cfe-dev] ASAN reporting heap overrun when doing a partial store to extended vector

Akira Hatanaka via cfe-dev cfe-dev at lists.llvm.org
Tue Mar 3 16:56:54 PST 2020


Does the following code have undefined behavior?

$ cat test.c
typedef __attribute__((__ext_vector_type__(32))) unsigned short vec32;
typedef __attribute__((__ext_vector_type__(16))) unsigned short vec16;

void writeVec(vec32 *data) {
  vec16 value = 0xffff;
  data->lo = value;
}

void foo1() {
  vec32 *p = (vec32 *)malloc(sizeof(unsigned short) * 16);
  writeVec(p);
}

The code above causes ASAN to report a heap overrun because clang creates a vector with 32 elements using vector shuffling and writes it back via the pointer passed to writeVec.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200303/4af3d3bf/attachment.html>


More information about the cfe-dev mailing list