forked from OSchip/llvm-project
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). llvm-svn: 68245
This commit is contained in:
parent
afb066d1f5
commit
8d816d6cb5
|
@ -1441,8 +1441,6 @@ def err_ret_local_block : Error<
|
|||
// 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">;
|
||||
|
||||
|
|
|
@ -1000,10 +1000,11 @@ static void appendFieldAndPadding(CodeGenModule &CGM,
|
|||
}
|
||||
}
|
||||
|
||||
// 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 @@ GetAddrOfConstantCFString(const StringLiteral *Literal) {
|
|||
&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 @@ GetAddrOfConstantCFString(const StringLiteral *Literal) {
|
|||
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);
|
||||
|
|
|
@ -173,13 +173,6 @@ bool Sema::CheckObjCString(Expr *Arg) {
|
|||
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)
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
// RUN: clang %s -verify -fsyntax-only
|
||||
@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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue