[llvm] r282433 - Allow StringRef to be constructed from a null pointer.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 28 14:49:32 PDT 2016


Sorry, I take that back.  If this change had any effect on existing code,
then llvm-symbolizer should have been asserting before my patch

On Wed, Sep 28, 2016 at 2:47 PM Zachary Turner <zturner at google.com> wrote:

> That is quite surprising, I admit I haven't seen the stack trace, but I'm
> inclined to say that something is wrong with the bisection method.  The
> only thing this change could possibly do is allow an object to be
> constructed where previously a construction would have failed to compile.
> So if this change had any effect on existing code, then llvm-symbolizer
> shouldn't have even been compiling before.
>
> On Wed, Sep 28, 2016 at 2:36 PM Evgenii Stepanov <
> eugeni.stepanov at gmail.com> wrote:
>
> This change broke llvm-symbolizer on android/x86 (and only x86), SEGV
> at startup. Trying to get a stack trace...
>
> On Mon, Sep 26, 2016 at 1:08 PM, Zachary Turner via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
> > Author: zturner
> > Date: Mon Sep 26 15:08:05 2016
> > New Revision: 282433
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=282433&view=rev
> > Log:
> > Allow StringRef to be constructed from a null pointer.
> >
> > Differential Revision: https://reviews.llvm.org/D24904
> >
> > Modified:
> >     llvm/trunk/include/llvm/ADT/StringRef.h
> >
> > Modified: llvm/trunk/include/llvm/ADT/StringRef.h
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringRef.h?rev=282433&r1=282432&r2=282433&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/include/llvm/ADT/StringRef.h (original)
> > +++ llvm/trunk/include/llvm/ADT/StringRef.h Mon Sep 26 15:08:05 2016
> > @@ -73,14 +73,14 @@ namespace llvm {
> >      /// Construct an empty string ref.
> >      /*implicit*/ StringRef() : Data(nullptr), Length(0) {}
> >
> > +    /// Disable conversion from nullptr.  This prevents things like
> > +    /// if (S == nullptr)
> >      StringRef(std::nullptr_t) = delete;
> >
> >      /// Construct a string ref from a cstring.
> > +    LLVM_ATTRIBUTE_ALWAYS_INLINE
> >      /*implicit*/ StringRef(const char *Str)
> > -      : Data(Str) {
> > -        assert(Str && "StringRef cannot be built from a NULL argument");
> > -        Length = ::strlen(Str); // invoking strlen(NULL) is undefined
> behavior
> > -      }
> > +        : Data(Str), Length(Str ? ::strlen(Str) : 0) {}
> >
> >      /// Construct a string ref from a pointer and length.
> >      LLVM_ATTRIBUTE_ALWAYS_INLINE
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160928/27128e83/attachment.html>


More information about the llvm-commits mailing list