[cfe-commits] r65925 - in /cfe/trunk: lib/CodeGen/CodeGenTypes.cpp lib/CodeGen/CodeGenTypes.h test/CodeGen/bool-convert.c
Eli Friedman
eli.friedman at gmail.com
Mon Mar 2 20:48:01 PST 2009
Author: efriedma
Date: Mon Mar 2 22:48:01 2009
New Revision: 65925
URL: http://llvm.org/viewvc/llvm-project?rev=65925&view=rev
Log:
Fix for PR3687: use the memory representation for booleans when a
sub-type describes a memory location, like the pointee type of a pointer
or the element type of an array.
Added:
cfe/trunk/test/CodeGen/bool-convert.c
Modified:
cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
cfe/trunk/lib/CodeGen/CodeGenTypes.h
Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=65925&r1=65924&r2=65925&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Mon Mar 2 22:48:01 2009
@@ -91,7 +91,7 @@
// We can handle bare pointers here because we know that the only pointers
// to the Opaque type are P.second and from other types. Refining the
// opqaue type away will invalidate P.second, but we don't mind :).
- const llvm::Type *NT = ConvertTypeRecursive(P.first);
+ const llvm::Type *NT = ConvertTypeForMemRecursive(P.first);
P.second->refineAbstractTypeTo(NT);
}
@@ -115,6 +115,13 @@
return ResultType;
}
+const llvm::Type *CodeGenTypes::ConvertTypeForMemRecursive(QualType T) {
+ const llvm::Type *ResultType = ConvertTypeRecursive(T);
+ if (ResultType == llvm::Type::Int1Ty)
+ return llvm::IntegerType::get((unsigned)Context.getTypeSize(T));
+ return ResultType;
+}
+
/// ConvertTypeForMem - Convert type T into a llvm::Type. 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
@@ -245,18 +252,18 @@
"FIXME: We only handle trivial array types so far!");
// VLAs resolve to the innermost element type; this matches
// the return of alloca, and there isn't any obviously better choice.
- return ConvertTypeRecursive(A.getElementType());
+ return ConvertTypeForMemRecursive(A.getElementType());
}
case Type::IncompleteArray: {
const IncompleteArrayType &A = cast<IncompleteArrayType>(Ty);
assert(A.getIndexTypeQualifier() == 0 &&
"FIXME: We only handle trivial array types so far!");
// int X[] -> [0 x int]
- return llvm::ArrayType::get(ConvertTypeRecursive(A.getElementType()), 0);
+ return llvm::ArrayType::get(ConvertTypeForMemRecursive(A.getElementType()), 0);
}
case Type::ConstantArray: {
const ConstantArrayType &A = cast<ConstantArrayType>(Ty);
- const llvm::Type *EltTy = ConvertTypeRecursive(A.getElementType());
+ const llvm::Type *EltTy = ConvertTypeForMemRecursive(A.getElementType());
return llvm::ArrayType::get(EltTy, A.getSize().getZExtValue());
}
case Type::ExtVector:
@@ -481,7 +488,7 @@
FieldEnd = RD.field_end();
Field != FieldEnd; ++Field) {
uint64_t offset = RL.getFieldOffset(curField);
- const llvm::Type *Ty = CGT.ConvertTypeRecursive(Field->getType());
+ const llvm::Type *Ty = CGT.ConvertTypeForMemRecursive(Field->getType());
uint64_t size = CGT.getTargetData().getTypePaddedSizeInBits(Ty);
if (Field->isBitField()) {
Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.h?rev=65925&r1=65924&r2=65925&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.h Mon Mar 2 22:48:01 2009
@@ -144,6 +144,7 @@
/// 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 *ConvertTypeForMem(QualType T);
+ const llvm::Type *ConvertTypeForMemRecursive(QualType T);
/// GetFunctionType - Get the LLVM function type for \arg Info.
const llvm::FunctionType *GetFunctionType(const CGFunctionInfo &Info,
Added: cfe/trunk/test/CodeGen/bool-convert.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/bool-convert.c?rev=65925&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/bool-convert.c (added)
+++ cfe/trunk/test/CodeGen/bool-convert.c Mon Mar 2 22:48:01 2009
@@ -0,0 +1,7 @@
+// RUN: clang -emit-llvm < %s | grep i1 | count 1
+// All of these should uses the memory representation of _Bool
+struct teststruct1 {_Bool a, b;} test1;
+_Bool* test2;
+_Bool test3[10];
+_Bool (*test4)[];
+
More information about the cfe-commits
mailing list