[cfe-commits] r82515 - in /cfe/trunk/lib: AST/StmtProfile.cpp CodeGen/CodeGenModule.cpp Sema/SemaChecking.cpp

Daniel Dunbar daniel at zuster.org
Mon Sep 21 20:27:52 PDT 2009


Author: ddunbar
Date: Mon Sep 21 22:27:52 2009
New Revision: 82515

URL: http://llvm.org/viewvc/llvm-project?rev=82515&view=rev
Log:
Switch a few clients over to StringLiteral::getString.
 - Switching all of them out-of-my-current-scope-of-interest, sorry.

Modified:
    cfe/trunk/lib/AST/StmtProfile.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/lib/AST/StmtProfile.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtProfile.cpp?rev=82515&r1=82514&r2=82515&view=diff

==============================================================================
--- cfe/trunk/lib/AST/StmtProfile.cpp (original)
+++ cfe/trunk/lib/AST/StmtProfile.cpp Mon Sep 21 22:27:52 2009
@@ -237,7 +237,7 @@
 
 void StmtProfiler::VisitStringLiteral(StringLiteral *S) {
   VisitExpr(S);
-  ID.AddString(S->getStrData(), S->getStrData() + S->getByteLength());
+  ID.AddString(S->getString());
   ID.AddBoolean(S->isWide());
 }
 

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=82515&r1=82514&r2=82515&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Sep 21 22:27:52 2009
@@ -1310,14 +1310,11 @@
                          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 @@
     // 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.

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=82515&r1=82514&r2=82515&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Sep 21 22:27:52 2009
@@ -447,17 +447,13 @@
     return true;
   }
 
-  const char *Data = Literal->getStrData();
-  unsigned Length = Literal->getByteLength();
+  llvm::StringRef Str = Literal->getString();
+  size_t NullLoc = Str.find('\0');
 
-  for (unsigned i = 0; i < Length; ++i) {
-    if (!Data[i]) {
-      Diag(getLocationOfStringLiteralByte(Literal, i),
-           diag::warn_cfstring_literal_contains_nul_character)
-        << Arg->getSourceRange();
-      break;
-    }
-  }
+  if (NullLoc != llvm::StringRef::npos)
+    Diag(getLocationOfStringLiteralByte(Literal, NullLoc),
+         diag::warn_cfstring_literal_contains_nul_character)
+      << Arg->getSourceRange();
 
   return false;
 }





More information about the cfe-commits mailing list