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

Evgenii Stepanov via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 28 14:36:10 PDT 2016


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


More information about the llvm-commits mailing list