[cfe-commits] r68245 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/CodeGen/CodeGenModule.cpp lib/Sema/SemaChecking.cpp test/SemaObjC/ucn-objc-string.m
Steve Naroff
snaroff at apple.com
Wed Apr 1 14:16:32 PDT 2009
Author: snaroff
Date: Wed Apr 1 16:16:31 2009
New Revision: 68245
URL: http://llvm.org/viewvc/llvm-project?rev=68245&view=rev
Log:
CodeGenModule::GetAddrOfConstantCFString():
- Finish up support for converting UTF8->UTF16 to support ObjC @"string" constants.
Remove warning from CheckObjCString.
As the FIXME in the test case indicates, I still have a bug to work out (apparently with \u handling).
Added:
cfe/trunk/test/SemaObjC/ucn-objc-string.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=68245&r1=68244&r2=68245&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Apr 1 16:16:31 2009
@@ -1441,8 +1441,6 @@
// CFString checking
def err_cfstring_literal_not_string_constant : Error<
"CFString literal is not a string constant">;
-def warn_cfstring_literal_contains_non_ascii_character : Warning<
- "CFString literal contains non-ASCII character">;
def warn_cfstring_literal_contains_nul_character : Warning<
"CFString literal contains NUL character">;
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=68245&r1=68244&r2=68245&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed Apr 1 16:16:31 2009
@@ -1000,10 +1000,11 @@
}
}
-// We still need to work out the details of handling UTF-16.
-// See: <rdr://2996215>
llvm::Constant *CodeGenModule::
GetAddrOfConstantCFString(const StringLiteral *Literal) {
+ std::string str;
+ unsigned StringLength;
+
bool isUTF16 = false;
if (Literal->containsNonAsciiOrNull()) {
// Convert from UTF-8 to UTF-16.
@@ -1016,10 +1017,14 @@
&ToPtr, ToPtr+Literal->getByteLength(),
strictConversion);
assert(Result == conversionOK && "UTF-8 to UTF-16 conversion failed");
+
+ StringLength = ToPtr-&ToBuf[0];
+ str.assign((char *)&ToBuf[0], StringLength*2); // Twice as many UTF8 chars.
isUTF16 = true;
- // FIXME: Do something with the converted value!
+ } else {
+ str.assign(Literal->getStrData(), Literal->getByteLength());
+ StringLength = str.length();
}
- std::string str(Literal->getStrData(), Literal->getByteLength());
llvm::StringMapEntry<llvm::Constant *> &Entry =
CFConstantStringMap.GetOrCreateValue(&str[0], &str[str.length()]);
@@ -1093,7 +1098,7 @@
NextField = 0;
Ty = getTypes().ConvertType(getContext().LongTy);
appendFieldAndPadding(*this, Fields, CurField, NextField,
- llvm::ConstantInt::get(Ty, str.length()), CFRD, STy);
+ llvm::ConstantInt::get(Ty, StringLength), CFRD, STy);
// The struct.
C = llvm::ConstantStruct::get(STy, Fields);
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=68245&r1=68244&r2=68245&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Apr 1 16:16:31 2009
@@ -173,13 +173,6 @@
unsigned Length = Literal->getByteLength();
for (unsigned i = 0; i < Length; ++i) {
- if (!isascii(Data[i])) {
- Diag(getLocationOfStringLiteralByte(Literal, i),
- diag::warn_cfstring_literal_contains_non_ascii_character)
- << Arg->getSourceRange();
- break;
- }
-
if (!Data[i]) {
Diag(getLocationOfStringLiteralByte(Literal, i),
diag::warn_cfstring_literal_contains_nul_character)
Added: cfe/trunk/test/SemaObjC/ucn-objc-string.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/ucn-objc-string.m?rev=68245&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/ucn-objc-string.m (added)
+++ cfe/trunk/test/SemaObjC/ucn-objc-string.m Wed Apr 1 16:16:31 2009
@@ -0,0 +1,13 @@
+// RUN: clang %s -verify -fsyntax-only
+ at class NSString;
+extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));
+
+int main() {
+ NSLog(@"Hiâ¦");
+ NSLog(@"Exposé");
+ // FIXME: the following 2 are still not working (will investigate).
+ //NSLog(@"hello \u2192 \u2603 \u2190 world");
+ //NSLog(@"\U00010400\U0001D12B");
+ return 0;
+}
+
More information about the cfe-commits
mailing list