diff options
| author | Chris Lattner <sabre@nondot.org> | 2007-12-09 23:49:42 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2007-12-09 23:49:42 +0000 |
| commit | c25c42f3ca3436d3b90e770d5488286043da956b (patch) | |
| tree | 1fa8f3fcd8ee9eedc54e33659318ffab9a9d8f63 /clang/CodeGen/CodeGenModule.cpp | |
| parent | 92c4e44da199cf3a800b3bf461f9cbcadc497e5f (diff) | |
| download | bcm5719-llvm-c25c42f3ca3436d3b90e770d5488286043da956b.tar.gz bcm5719-llvm-c25c42f3ca3436d3b90e770d5488286043da956b.zip | |
Implement codegen support for:
char text[8] = "string";
Big fixme remains.
llvm-svn: 44750
Diffstat (limited to 'clang/CodeGen/CodeGenModule.cpp')
| -rw-r--r-- | clang/CodeGen/CodeGenModule.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/clang/CodeGen/CodeGenModule.cpp b/clang/CodeGen/CodeGenModule.cpp index ecabb814ae7..55336510c63 100644 --- a/clang/CodeGen/CodeGenModule.cpp +++ b/clang/CodeGen/CodeGenModule.cpp @@ -407,6 +407,27 @@ static llvm::Constant *GenerateConstantExpr(const Expr *Expression, return llvm::ConstantExpr::getGetElementPtr(C, Ops, 2); } + // If this is an implicit cast of a string literal to an array type, this + // must be a string initializing an array. Don't emit it as the address of + // the string, emit the string data itself as an inline array. + if (const StringLiteral *String = + dyn_cast<StringLiteral>(ICExpr->getSubExpr())) + if (const ArrayType *AT = ICExpr->getType()->getAsArrayType()) { + // Verify that this is an array of char or wchar. Array of const char* + // can be initialized with a string literal, which does not expand the + // characters inline. + // FIXME: What about wchar_t?? + if (AT->getElementType()->isCharType()) { + const char *StrData = String->getStrData(); + unsigned Len = String->getByteLength(); + llvm::Constant *C = + llvm::ConstantArray::get(std::string(StrData, StrData + Len)); + // FIXME: This should return a string of the proper type: this + // mishandles things like 'char x[4] = "1234567"; + return C; + } + } + return GenerateConstantCast(ICExpr->getSubExpr(), type, CGM); } |

