diff --git a/lib/Support/Twine.cpp b/lib/Support/Twine.cpp index 4f6f479a7ea..75cea2961a9 100644 --- a/lib/Support/Twine.cpp +++ b/lib/Support/Twine.cpp @@ -31,10 +31,18 @@ StringRef Twine::toStringRef(SmallVectorImpl &Out) const { } StringRef Twine::toNullTerminatedStringRef(SmallVectorImpl &Out) const { - if (isSingleStringRef()) { - StringRef sr = getSingleStringRef(); - if (*(sr.begin() + sr.size()) == 0) - return sr; + if (isUnary()) { + switch (getLHSKind()) { + case CStringKind: + // Already null terminated, yay! + return StringRef(static_cast(LHS)); + case StdStringKind: { + const std::string *str = static_cast(LHS); + return StringRef(str->c_str(), str->size()); + } + default: + break; + } } toVector(Out); Out.push_back(0);