Revert "Switch a few clients over to StringLiteral::getString.", this is breaking some projects, but I don't have a test case yet.

llvm-svn: 82539
This commit is contained in:
Daniel Dunbar 2009-09-22 10:03:52 +00:00
parent 99e1174baf
commit b879c3c125
3 changed files with 21 additions and 12 deletions

View File

@ -237,7 +237,7 @@ void StmtProfiler::VisitImaginaryLiteral(ImaginaryLiteral *S) {
void StmtProfiler::VisitStringLiteral(StringLiteral *S) { void StmtProfiler::VisitStringLiteral(StringLiteral *S) {
VisitExpr(S); VisitExpr(S);
ID.AddString(S->getString()); ID.AddString(S->getStrData(), S->getStrData() + S->getByteLength());
ID.AddBoolean(S->isWide()); ID.AddBoolean(S->isWide());
} }

View File

@ -1310,12 +1310,15 @@ GetConstantCFStringEntry(llvm::StringMap<llvm::Constant*> &Map,
bool TargetIsLSB, bool TargetIsLSB,
bool &IsUTF16, bool &IsUTF16,
unsigned &StringLength) { unsigned &StringLength) {
// Check for simple case.
if (!Literal->containsNonAsciiOrNull())
return Map.GetOrCreateValue(Literal->getString());
unsigned NumBytes = Literal->getByteLength(); unsigned NumBytes = Literal->getByteLength();
// Check for simple case.
if (!Literal->containsNonAsciiOrNull()) {
StringLength = NumBytes;
return Map.GetOrCreateValue(llvm::StringRef(Literal->getStrData(),
StringLength));
}
// Otherwise, convert the UTF8 literals into a byte string. // Otherwise, convert the UTF8 literals into a byte string.
llvm::SmallVector<UTF16, 128> ToBuf(NumBytes); llvm::SmallVector<UTF16, 128> ToBuf(NumBytes);
const UTF8 *FromPtr = (UTF8 *)Literal->getStrData(); const UTF8 *FromPtr = (UTF8 *)Literal->getStrData();
@ -1330,7 +1333,9 @@ GetConstantCFStringEntry(llvm::StringMap<llvm::Constant*> &Map,
// FIXME: Have Sema::CheckObjCString() validate the UTF-8 string and remove // FIXME: Have Sema::CheckObjCString() validate the UTF-8 string and remove
// this duplicate code. // this duplicate code.
assert(Result == sourceIllegal && "UTF-8 to UTF-16 conversion failed"); assert(Result == sourceIllegal && "UTF-8 to UTF-16 conversion failed");
return Map.GetOrCreateValue(Literal->getString()); StringLength = NumBytes;
return Map.GetOrCreateValue(llvm::StringRef(Literal->getStrData(),
StringLength));
} }
// ConvertUTF8toUTF16 returns the length in ToPtr. // ConvertUTF8toUTF16 returns the length in ToPtr.

View File

@ -447,13 +447,17 @@ bool Sema::CheckObjCString(Expr *Arg) {
return true; return true;
} }
llvm::StringRef Str = Literal->getString(); const char *Data = Literal->getStrData();
size_t NullLoc = Str.find('\0'); unsigned Length = Literal->getByteLength();
if (NullLoc != llvm::StringRef::npos) for (unsigned i = 0; i < Length; ++i) {
Diag(getLocationOfStringLiteralByte(Literal, NullLoc), if (!Data[i]) {
Diag(getLocationOfStringLiteralByte(Literal, i),
diag::warn_cfstring_literal_contains_nul_character) diag::warn_cfstring_literal_contains_nul_character)
<< Arg->getSourceRange(); << Arg->getSourceRange();
break;
}
}
return false; return false;
} }