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

NAKAMURA Takumi via llvm-dev llvm-dev at lists.llvm.org
Mon May 22 05:04:21 PDT 2017


> llvm::ArrayRef<SDValue> Ops = { Lo, Hi };

{Lo, Hi} is a temporary object in stack and it is supposed to vanish after
the statement.
You may write like ; (See X86ISelLowering.cpp:21709)

  SDValue Ops[] = { Lo, Hi };
  return DAG.getMergeValues(Ops, dl);

ArrayRef's constructor recognizes and infers array.


On Mon, May 22, 2017 at 8:27 PM 陳韋任 via llvm-dev <llvm-dev at lists.llvm.org>
wrote:

> 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
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170522/6b903a31/attachment.html>


More information about the llvm-dev mailing list