aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-09-22 10:03:52 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-09-22 10:03:52 +0000
commitf015b034159d40e7033309e50036804eb1971787 (patch)
tree7d4989d9817e020f41260da7ebdc5db422b7e59a
parent7f8b57aa3558ed079358637a2a48db7d2fefb4b2 (diff)
Revert "Switch a few clients over to StringLiteral::getString.", this is breaking some projects, but I don't have a test case yet.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82539 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/AST/StmtProfile.cpp2
-rw-r--r--lib/CodeGen/CodeGenModule.cpp15
-rw-r--r--lib/Sema/SemaChecking.cpp18
3 files changed, 22 insertions, 13 deletions
diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp
index c4d42f6be2..5a5badd289 100644
--- a/lib/AST/StmtProfile.cpp
+++ b/lib/AST/StmtProfile.cpp
@@ -237,7 +237,7 @@ void StmtProfiler::VisitImaginaryLiteral(ImaginaryLiteral *S) {
void StmtProfiler::VisitStringLiteral(StringLiteral *S) {
VisitExpr(S);
- ID.AddString(S->getString());
+ ID.AddString(S->getStrData(), S->getStrData() + S->getByteLength());
ID.AddBoolean(S->isWide());
}
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index ac0c6c3fae..af9f7e91f3 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -1310,12 +1310,15 @@ GetConstantCFStringEntry(llvm::StringMap<llvm::Constant*> &Map,
bool TargetIsLSB,
bool &IsUTF16,
unsigned &StringLength) {
- // Check for simple case.
- if (!Literal->containsNonAsciiOrNull())
- return Map.GetOrCreateValue(Literal->getString());
-
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.
llvm::SmallVector<UTF16, 128> ToBuf(NumBytes);
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
// this duplicate code.
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.
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index 0da06a99d5..1e26c3507b 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -447,13 +447,17 @@ bool Sema::CheckObjCString(Expr *Arg) {
return true;
}
- 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();
+ 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;
+ }
+ }
return false;
}