void StmtProfiler::VisitStringLiteral(StringLiteral *S) {
VisitExpr(S);
- ID.AddString(S->getStrData(), S->getStrData() + S->getByteLength());
+ ID.AddString(S->getString());
ID.AddBoolean(S->isWide());
}
bool TargetIsLSB,
bool &IsUTF16,
unsigned &StringLength) {
- unsigned NumBytes = Literal->getByteLength();
-
// Check for simple case.
- if (!Literal->containsNonAsciiOrNull()) {
- StringLength = NumBytes;
- return Map.GetOrCreateValue(llvm::StringRef(Literal->getStrData(),
- StringLength));
- }
+ if (!Literal->containsNonAsciiOrNull())
+ return Map.GetOrCreateValue(Literal->getString());
+
+ unsigned NumBytes = Literal->getByteLength();
// Otherwise, convert the UTF8 literals into a byte string.
llvm::SmallVector<UTF16, 128> ToBuf(NumBytes);
// FIXME: Have Sema::CheckObjCString() validate the UTF-8 string and remove
// this duplicate code.
assert(Result == sourceIllegal && "UTF-8 to UTF-16 conversion failed");
- StringLength = NumBytes;
- return Map.GetOrCreateValue(llvm::StringRef(Literal->getStrData(),
- StringLength));
+ return Map.GetOrCreateValue(Literal->getString());
}
// ConvertUTF8toUTF16 returns the length in ToPtr.
return true;
}
- const char *Data = Literal->getStrData();
- unsigned Length = Literal->getByteLength();
-
- for (unsigned i = 0; i < Length; ++i) {
- if (!Data[i]) {
- Diag(getLocationOfStringLiteralByte(Literal, i),
- diag::warn_cfstring_literal_contains_nul_character)
- << Arg->getSourceRange();
- break;
- }
- }
+ llvm::StringRef Str = Literal->getString();
+ size_t NullLoc = Str.find('\0');
+
+ if (NullLoc != llvm::StringRef::npos)
+ Diag(getLocationOfStringLiteralByte(Literal, NullLoc),
+ diag::warn_cfstring_literal_contains_nul_character)
+ << Arg->getSourceRange();
return false;
}