]> granicus.if.org Git - clang/commitdiff
Switch a few clients over to StringLiteral::getString.
authorDaniel Dunbar <daniel@zuster.org>
Tue, 22 Sep 2009 03:27:52 +0000 (03:27 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 22 Sep 2009 03:27:52 +0000 (03:27 +0000)
 - Switching all of them out-of-my-current-scope-of-interest, sorry.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82515 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/StmtProfile.cpp
lib/CodeGen/CodeGenModule.cpp
lib/Sema/SemaChecking.cpp

index 5a5badd28910682c7f933fe0cbed45a8a62bbfad..c4d42f6be228010a4d4b544037c286e8281d329e 100644 (file)
@@ -237,7 +237,7 @@ void StmtProfiler::VisitImaginaryLiteral(ImaginaryLiteral *S) {
 
 void StmtProfiler::VisitStringLiteral(StringLiteral *S) {
   VisitExpr(S);
-  ID.AddString(S->getStrData(), S->getStrData() + S->getByteLength());
+  ID.AddString(S->getString());
   ID.AddBoolean(S->isWide());
 }
 
index af9f7e91f3f04d51f4f8089089fa852cfd38b0c8..ac0c6c3faecafa2aecb7abbcb9913e1d37a0b7b3 100644 (file)
@@ -1310,14 +1310,11 @@ GetConstantCFStringEntry(llvm::StringMap<llvm::Constant*> &Map,
                          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);
@@ -1333,9 +1330,7 @@ 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");
-    StringLength = NumBytes;
-    return Map.GetOrCreateValue(llvm::StringRef(Literal->getStrData(),
-                                                StringLength));
+    return Map.GetOrCreateValue(Literal->getString());
   }
 
   // ConvertUTF8toUTF16 returns the length in ToPtr.
index 1e26c3507bbf5f1aeefa69e727a1c640af755db5..0da06a99d595408f44d460b6d7d2db8657edba2e 100644 (file)
@@ -447,17 +447,13 @@ bool Sema::CheckObjCString(Expr *Arg) {
     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;
 }