diff options
author | Chris Lattner <sabre@nondot.org> | 2008-01-09 18:47:25 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-01-09 18:47:25 +0000 |
commit | 19009e6fe7e0f51d2e49f4c94928a048c11c5281 (patch) | |
tree | 69ff6fa0eee830ef2aba3b4f0771b72303c24607 /CodeGen/CodeGenTypes.cpp | |
parent | 88f50f31d84185827a8f765dd611134bcaface7b (diff) |
implement proper support for _Bool in memory, which is usually i8, not i1.
This fixes a crash reported by Seo Sanghyeon
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45778 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'CodeGen/CodeGenTypes.cpp')
-rw-r--r-- | CodeGen/CodeGenTypes.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/CodeGen/CodeGenTypes.cpp b/CodeGen/CodeGenTypes.cpp index 0de6dc8b5e..e2a5798ba8 100644 --- a/CodeGen/CodeGenTypes.cpp +++ b/CodeGen/CodeGenTypes.cpp @@ -149,6 +149,25 @@ const llvm::Type *CodeGenTypes::ConvertType(QualType T) { return ResultType; } +/// ConvertTypeForMem - Convert type T into a llvm::Type. Maintain and use +/// type cache through TypeHolderMap. This differs from ConvertType in that +/// it is used to convert to the memory representation for a type. For +/// example, the scalar representation for _Bool is i1, but the memory +/// representation is usually i8 or i32, depending on the target. +const llvm::Type *CodeGenTypes::ConvertTypeForMem(QualType T) { + const llvm::Type *R = ConvertType(T); + + // If this is a non-bool type, don't map it. + if (R != llvm::Type::Int1Ty) + return R; + + // Otherwise, return an integer of the target-specified size. + unsigned BoolWidth = (unsigned)Context.getTypeSize(T, SourceLocation()); + return llvm::IntegerType::get(BoolWidth); + +} + + const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) { const clang::Type &Ty = *T.getCanonicalType(); @@ -165,8 +184,7 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) { return llvm::IntegerType::get(8); case BuiltinType::Bool: - // FIXME: This is very strange. We want scalars to be i1, but in memory - // they can be i1 or i32. Should the codegen handle this issue? + // Note that we always return bool as i1 for use as a scalar type. return llvm::Type::Int1Ty; case BuiltinType::Char_S: |