[LLVMdev] Addressing const reference in ArrayRef
Joey Ye
joey.ye.cc at gmail.com
Tue Aug 19 20:26:44 PDT 2014
Analyzing why GCC failed to build LLVM recently, one root cause lies
in definition of ArrayRef:
// ArrayRef.h:
ArrayRef(const T &OneElt) : Data(&OneElt), Length(1) {}
Here address of const reference is taken and stored to an object. It
is believed that live range of const reference is only at the function
call site, escaping of its address to an object with a longer live
range is invalid. Referring to the case and discussion here:
https://gcc.gnu.org/ml/gcc/2014-08/msg00173.html
So I would suggest to fix ArrayRef. Adding a non-const version of
constructor should work, but it still leaves the vulnerability in
const version, which I'd expect on people in the community to work out
a solution.
ArrayRef(T &OneElt) : Data(&OneElt), Length(1) {}
Thanks,
Joey
More information about the llvm-dev
mailing list