diff options
author | Sean Callanan <scallanan@apple.com> | 2011-02-10 22:17:53 +0000 |
---|---|---|
committer | Sean Callanan <scallanan@apple.com> | 2011-02-10 22:17:53 +0000 |
commit | 229ce2d5b1ea23f8835779832f977f958402dc1c (patch) | |
tree | 6c59444d00502906278f3f8c73f0eeea4f73cfed /lldb/source/Expression/IRForTarget.cpp | |
parent | 9524110d98b8e10e573fc901accb9ed745b12786 (diff) | |
download | bcm5719-llvm-229ce2d5b1ea23f8835779832f977f958402dc1c.tar.gz bcm5719-llvm-229ce2d5b1ea23f8835779832f977f958402dc1c.zip |
Fixes for two bugs:
- Objective-C constant strings were being
NULL-terminated erroneously.
- Empty Objective-C constant strings were not
being generated correctly.
Also added the template for a test of these
fixes.
llvm-svn: 125314
Diffstat (limited to 'lldb/source/Expression/IRForTarget.cpp')
-rw-r--r-- | lldb/source/Expression/IRForTarget.cpp | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/lldb/source/Expression/IRForTarget.cpp b/lldb/source/Expression/IRForTarget.cpp index 4601a3f4138..f9ea7e1ab38 100644 --- a/lldb/source/Expression/IRForTarget.cpp +++ b/lldb/source/Expression/IRForTarget.cpp @@ -478,13 +478,18 @@ IRForTarget::RewriteObjCConstString (llvm::Module &llvm_module, m_CFStringCreateWithBytes = ConstantExpr::getIntToPtr(CFSCWB_addr_int, CFSCWB_ptr_ty); } - ConstantArray *string_array = dyn_cast<ConstantArray>(cstr->getInitializer()); + ConstantArray *string_array; + + if (cstr) + string_array = dyn_cast<ConstantArray>(cstr->getInitializer()); + else + string_array = NULL; SmallVector <Value*, 5> CFSCWB_arguments; Constant *alloc_arg = Constant::getNullValue(i8_ptr_ty); - Constant *bytes_arg = ConstantExpr::getBitCast(cstr, i8_ptr_ty); - Constant *numBytes_arg = ConstantInt::get(intptr_ty, string_array->getType()->getNumElements(), false); + Constant *bytes_arg = cstr ? ConstantExpr::getBitCast(cstr, i8_ptr_ty) : Constant::getNullValue(i8_ptr_ty); + Constant *numBytes_arg = ConstantInt::get(intptr_ty, cstr ? string_array->getType()->getNumElements() - 1 : 0, false); Constant *encoding_arg = ConstantInt::get(i32_ty, 0x0600, false); /* 0x0600 is kCFStringEncodingASCII */ Constant *isExternal_arg = ConstantInt::get(i8_ty, 0x0, false); /* 0x0 is false */ @@ -664,9 +669,8 @@ IRForTarget::RewriteObjCConstStrings(Module &llvm_module, Function &llvm_functio return false; } - - ConstantArray *cstr_array = dyn_cast<ConstantArray>(cstr_global->getInitializer()); - + + /* if (!cstr_array) { if (log) @@ -688,9 +692,20 @@ IRForTarget::RewriteObjCConstStrings(Module &llvm_module, Function &llvm_functio return false; } + */ + + ConstantArray *cstr_array = dyn_cast<ConstantArray>(cstr_global->getInitializer()); if (log) - log->Printf("Found NSString constant %s, which contains \"%s\"", vi->first(), cstr_array->getAsString().c_str()); + { + if (cstr_array) + log->Printf("Found NSString constant %s, which contains \"%s\"", vi->first(), cstr_array->getAsString().c_str()); + else + log->Printf("Found NSString constant %s, which contains \"\"", vi->first()); + } + + if (!cstr_array) + cstr_global = NULL; if (!RewriteObjCConstString(llvm_module, nsstring_global, cstr_global, FirstEntryInstruction)) { |