[llvm-dev] The right usage of llvm::ArrayRef

陳韋任 via llvm-dev llvm-dev at lists.llvm.org
Mon May 22 04:26:51 PDT 2017


Hi All,

  I debug a Release build LLVM crash, and find the culprit. The code
snippet below,

    llvm::ArrayRef<SDValue> Ops = { Lo, Hi }; // should be `SDValue Ops[2] =
{ Lo, Hi };`
    return DAG.getMergeValues(Ops, dl);

Turns out a nullptr is dereferenced in DAG.getMergeValues, thus I have
segfault.

>From the comment on [1], it says:

    This class does not own the underlying data, it is expected to be used
in situations
    where the data resides in some other buffer, whose lifetime extends
past that of the
    ArrayRef. For this reason, it is not in general safe to store an
ArrayRef.

I feel somehow the comment explain why I get the segfault, but not sure
about that.
Would someone kindly explain why?

  Thanks.

[1] http://llvm.org/doxygen/classllvm_1_1ArrayRef.html

Regards,
chenwj

-- 
Wei-Ren Chen (陳韋任)
Homepage: https://people.cs.nctu.edu.tw/~chenwj
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170522/1625b126/attachment.html>


More information about the llvm-dev mailing list