remove the source location arguments to various target query methods.

llvm-svn: 47954
This commit is contained in:
Chris Lattner 2008-03-05 18:54:05 +00:00
parent ae3429f5f1
commit 37e0587839
26 changed files with 168 additions and 299 deletions

View File

@ -133,7 +133,7 @@ void ASTContext::InitBuiltinTypes() {
// C99 6.2.5p2. // C99 6.2.5p2.
InitBuiltinType(BoolTy, BuiltinType::Bool); InitBuiltinType(BoolTy, BuiltinType::Bool);
// C99 6.2.5p3. // C99 6.2.5p3.
if (Target.isCharSigned(FullSourceLoc())) if (Target.isCharSigned())
InitBuiltinType(CharTy, BuiltinType::Char_S); InitBuiltinType(CharTy, BuiltinType::Char_S);
else else
InitBuiltinType(CharTy, BuiltinType::Char_U); InitBuiltinType(CharTy, BuiltinType::Char_U);
@ -180,7 +180,7 @@ void ASTContext::InitBuiltinTypes() {
/// getTypeSize - Return the size of the specified type, in bits. This method /// getTypeSize - Return the size of the specified type, in bits. This method
/// does not work on incomplete types. /// does not work on incomplete types.
std::pair<uint64_t, unsigned> std::pair<uint64_t, unsigned>
ASTContext::getTypeInfo(QualType T, SourceLocation L) { ASTContext::getTypeInfo(QualType T) {
T = T.getCanonicalType(); T = T.getCanonicalType();
uint64_t Size; uint64_t Size;
unsigned Align; unsigned Align;
@ -195,8 +195,7 @@ ASTContext::getTypeInfo(QualType T, SourceLocation L) {
case Type::ConstantArray: { case Type::ConstantArray: {
ConstantArrayType *CAT = cast<ConstantArrayType>(T); ConstantArrayType *CAT = cast<ConstantArrayType>(T);
std::pair<uint64_t, unsigned> EltInfo = std::pair<uint64_t, unsigned> EltInfo = getTypeInfo(CAT->getElementType());
getTypeInfo(CAT->getElementType(), L);
Size = EltInfo.first*CAT->getSize().getZExtValue(); Size = EltInfo.first*CAT->getSize().getZExtValue();
Align = EltInfo.second; Align = EltInfo.second;
break; break;
@ -204,7 +203,7 @@ ASTContext::getTypeInfo(QualType T, SourceLocation L) {
case Type::OCUVector: case Type::OCUVector:
case Type::Vector: { case Type::Vector: {
std::pair<uint64_t, unsigned> EltInfo = std::pair<uint64_t, unsigned> EltInfo =
getTypeInfo(cast<VectorType>(T)->getElementType(), L); getTypeInfo(cast<VectorType>(T)->getElementType());
Size = EltInfo.first*cast<VectorType>(T)->getNumElements(); Size = EltInfo.first*cast<VectorType>(T)->getNumElements();
// FIXME: Vector alignment is not the alignment of its elements. // FIXME: Vector alignment is not the alignment of its elements.
Align = EltInfo.second; Align = EltInfo.second;
@ -220,62 +219,62 @@ ASTContext::getTypeInfo(QualType T, SourceLocation L) {
case BuiltinType::Void: case BuiltinType::Void:
assert(0 && "Incomplete types have no size!"); assert(0 && "Incomplete types have no size!");
case BuiltinType::Bool: case BuiltinType::Bool:
Target.getBoolInfo(Size, Align, getFullLoc(L)); Target.getBoolInfo(Size, Align);
break; break;
case BuiltinType::Char_S: case BuiltinType::Char_S:
case BuiltinType::Char_U: case BuiltinType::Char_U:
case BuiltinType::UChar: case BuiltinType::UChar:
case BuiltinType::SChar: case BuiltinType::SChar:
Target.getCharInfo(Size, Align, getFullLoc(L)); Target.getCharInfo(Size, Align);
break; break;
case BuiltinType::UShort: case BuiltinType::UShort:
case BuiltinType::Short: case BuiltinType::Short:
Target.getShortInfo(Size, Align, getFullLoc(L)); Target.getShortInfo(Size, Align);
break; break;
case BuiltinType::UInt: case BuiltinType::UInt:
case BuiltinType::Int: case BuiltinType::Int:
Target.getIntInfo(Size, Align, getFullLoc(L)); Target.getIntInfo(Size, Align);
break; break;
case BuiltinType::ULong: case BuiltinType::ULong:
case BuiltinType::Long: case BuiltinType::Long:
Target.getLongInfo(Size, Align, getFullLoc(L)); Target.getLongInfo(Size, Align);
break; break;
case BuiltinType::ULongLong: case BuiltinType::ULongLong:
case BuiltinType::LongLong: case BuiltinType::LongLong:
Target.getLongLongInfo(Size, Align, getFullLoc(L)); Target.getLongLongInfo(Size, Align);
break; break;
case BuiltinType::Float: case BuiltinType::Float:
Target.getFloatInfo(Size, Align, F, getFullLoc(L)); Target.getFloatInfo(Size, Align, F);
break; break;
case BuiltinType::Double: case BuiltinType::Double:
Target.getDoubleInfo(Size, Align, F, getFullLoc(L)); Target.getDoubleInfo(Size, Align, F);
break; break;
case BuiltinType::LongDouble: case BuiltinType::LongDouble:
Target.getLongDoubleInfo(Size, Align, F, getFullLoc(L)); Target.getLongDoubleInfo(Size, Align, F);
break; break;
} }
break; break;
} }
case Type::ASQual: case Type::ASQual:
return getTypeInfo(QualType(cast<ASQualType>(T)->getBaseType(), 0), L); // FIXME: Pointers into different addr spaces could have different sizes and
// alignment requirements: getPointerInfo should take an AddrSpace.
return getTypeInfo(QualType(cast<ASQualType>(T)->getBaseType(), 0));
case Type::ObjCQualifiedId: case Type::ObjCQualifiedId:
Target.getPointerInfo(Size, Align, getFullLoc(L));
break;
case Type::Pointer: case Type::Pointer:
Target.getPointerInfo(Size, Align, getFullLoc(L)); Target.getPointerInfo(Size, Align);
break; break;
case Type::Reference: case Type::Reference:
// "When applied to a reference or a reference type, the result is the size // "When applied to a reference or a reference type, the result is the size
// of the referenced type." C++98 5.3.3p2: expr.sizeof. // of the referenced type." C++98 5.3.3p2: expr.sizeof.
// FIXME: This is wrong for struct layout: a reference in a struct has // FIXME: This is wrong for struct layout: a reference in a struct has
// pointer size. // pointer size.
return getTypeInfo(cast<ReferenceType>(T)->getReferenceeType(), L); return getTypeInfo(cast<ReferenceType>(T)->getReferenceeType());
case Type::Complex: { case Type::Complex: {
// Complex types have the same alignment as their elements, but twice the // Complex types have the same alignment as their elements, but twice the
// size. // size.
std::pair<uint64_t, unsigned> EltInfo = std::pair<uint64_t, unsigned> EltInfo =
getTypeInfo(cast<ComplexType>(T)->getElementType(), L); getTypeInfo(cast<ComplexType>(T)->getElementType());
Size = EltInfo.first*2; Size = EltInfo.first*2;
Align = EltInfo.second; Align = EltInfo.second;
break; break;
@ -283,11 +282,11 @@ ASTContext::getTypeInfo(QualType T, SourceLocation L) {
case Type::Tagged: case Type::Tagged:
TagType *TT = cast<TagType>(T); TagType *TT = cast<TagType>(T);
if (RecordType *RT = dyn_cast<RecordType>(TT)) { if (RecordType *RT = dyn_cast<RecordType>(TT)) {
const ASTRecordLayout &Layout = getASTRecordLayout(RT->getDecl(), L); const ASTRecordLayout &Layout = getASTRecordLayout(RT->getDecl());
Size = Layout.getSize(); Size = Layout.getSize();
Align = Layout.getAlignment(); Align = Layout.getAlignment();
} else if (EnumDecl *ED = dyn_cast<EnumDecl>(TT->getDecl())) { } else if (EnumDecl *ED = dyn_cast<EnumDecl>(TT->getDecl())) {
return getTypeInfo(ED->getIntegerType(), L); return getTypeInfo(ED->getIntegerType());
} else { } else {
assert(0 && "Unimplemented type sizes!"); assert(0 && "Unimplemented type sizes!");
} }
@ -301,8 +300,7 @@ ASTContext::getTypeInfo(QualType T, SourceLocation L) {
/// getASTRecordLayout - Get or compute information about the layout of the /// getASTRecordLayout - Get or compute information about the layout of the
/// specified record (struct/union/class), which indicates its size and field /// specified record (struct/union/class), which indicates its size and field
/// position information. /// position information.
const ASTRecordLayout &ASTContext::getASTRecordLayout(const RecordDecl *D, const ASTRecordLayout &ASTContext::getASTRecordLayout(const RecordDecl *D) {
SourceLocation L) {
assert(D->isDefinition() && "Cannot get layout of forward declarations!"); assert(D->isDefinition() && "Cannot get layout of forward declarations!");
// Look up this layout, if already laid out, return what we have. // Look up this layout, if already laid out, return what we have.
@ -339,7 +337,7 @@ const ASTRecordLayout &ASTContext::getASTRecordLayout(const RecordDecl *D,
assert (BitWidthIsICE && "Invalid BitField size expression"); assert (BitWidthIsICE && "Invalid BitField size expression");
FieldSize = I.getZExtValue(); FieldSize = I.getZExtValue();
std::pair<uint64_t, unsigned> TypeInfo = getTypeInfo(FD->getType(), L); std::pair<uint64_t, unsigned> TypeInfo = getTypeInfo(FD->getType());
uint64_t TypeSize = TypeInfo.first; uint64_t TypeSize = TypeInfo.first;
if (const AlignedAttr *AA = FD->getAttr<AlignedAttr>()) if (const AlignedAttr *AA = FD->getAttr<AlignedAttr>())
@ -372,11 +370,11 @@ const ASTRecordLayout &ASTContext::getASTRecordLayout(const RecordDecl *D,
FieldAlign = 8; FieldAlign = 8;
else { else {
const ArrayType* ATy = FD->getType()->getAsArrayType(); const ArrayType* ATy = FD->getType()->getAsArrayType();
FieldAlign = getTypeAlign(ATy->getElementType(), L); FieldAlign = getTypeAlign(ATy->getElementType());
} }
FieldSize = 0; FieldSize = 0;
} else { } else {
std::pair<uint64_t, unsigned> FieldInfo = getTypeInfo(FD->getType(), L); std::pair<uint64_t, unsigned> FieldInfo = getTypeInfo(FD->getType());
FieldSize = FieldInfo.first; FieldSize = FieldInfo.first;
if (const AlignedAttr *AA = FD->getAttr<AlignedAttr>()) if (const AlignedAttr *AA = FD->getAttr<AlignedAttr>())
@ -408,7 +406,7 @@ const ASTRecordLayout &ASTContext::getASTRecordLayout(const RecordDecl *D,
// Union layout just puts each member at the start of the record. // Union layout just puts each member at the start of the record.
for (unsigned i = 0, e = D->getNumMembers(); i != e; ++i) { for (unsigned i = 0, e = D->getNumMembers(); i != e; ++i) {
const FieldDecl *FD = D->getMember(i); const FieldDecl *FD = D->getMember(i);
std::pair<uint64_t, unsigned> FieldInfo = getTypeInfo(FD->getType(), L); std::pair<uint64_t, unsigned> FieldInfo = getTypeInfo(FD->getType());
uint64_t FieldSize = FieldInfo.first; uint64_t FieldSize = FieldInfo.first;
unsigned FieldAlign = FieldInfo.second; unsigned FieldAlign = FieldInfo.second;
@ -1073,16 +1071,15 @@ static bool isTypeTypedefedAsBOOL(QualType T) {
/// getObjCEncodingTypeSize returns size of type for objective-c encoding /// getObjCEncodingTypeSize returns size of type for objective-c encoding
/// purpose. /// purpose.
int ASTContext::getObjCEncodingTypeSize(QualType type) { int ASTContext::getObjCEncodingTypeSize(QualType type) {
SourceLocation Loc; uint64_t sz = getTypeSize(type);
uint64_t sz = getTypeSize(type, Loc);
// Make all integer and enum types at least as large as an int // Make all integer and enum types at least as large as an int
if (sz > 0 && type->isIntegralType()) if (sz > 0 && type->isIntegralType())
sz = std::max(sz, getTypeSize(IntTy, Loc)); sz = std::max(sz, getTypeSize(IntTy));
// Treat arrays as pointers, since that's how they're passed in. // Treat arrays as pointers, since that's how they're passed in.
else if (type->isArrayType()) else if (type->isArrayType())
sz = getTypeSize(VoidPtrTy, Loc); sz = getTypeSize(VoidPtrTy);
return sz / getTypeSize(CharTy, Loc); return sz / getTypeSize(CharTy);
} }
/// getObjCEncodingForMethodDecl - Return the encoded type for this method /// getObjCEncodingForMethodDecl - Return the encoded type for this method
@ -1098,7 +1095,7 @@ void ASTContext::getObjCEncodingForMethodDecl(ObjCMethodDecl *Decl,
// Start with computing size of a pointer in number of bytes. // Start with computing size of a pointer in number of bytes.
// FIXME: There might(should) be a better way of doing this computation! // FIXME: There might(should) be a better way of doing this computation!
SourceLocation Loc; SourceLocation Loc;
int PtrSize = getTypeSize(VoidPtrTy, Loc) / getTypeSize(CharTy, Loc); int PtrSize = getTypeSize(VoidPtrTy) / getTypeSize(CharTy);
// The first two arguments (self and _cmd) are pointers; account for // The first two arguments (self and _cmd) are pointers; account for
// their size. // their size.
int ParmOffset = 2 * PtrSize; int ParmOffset = 2 * PtrSize;

View File

@ -510,8 +510,7 @@ bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const {
case CallExprClass: { case CallExprClass: {
const CallExpr *CE = cast<CallExpr>(this); const CallExpr *CE = cast<CallExpr>(this);
llvm::APSInt Result(32); llvm::APSInt Result(32);
Result.zextOrTrunc( Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
static_cast<uint32_t>(Ctx.getTypeSize(getType(), CE->getLocStart())));
if (CE->isBuiltinClassifyType(Result)) if (CE->isBuiltinClassifyType(Result))
return true; return true;
if (CE->isBuiltinConstantExpr()) if (CE->isBuiltinConstantExpr())
@ -673,23 +672,20 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
break; break;
case CharacterLiteralClass: { case CharacterLiteralClass: {
const CharacterLiteral *CL = cast<CharacterLiteral>(this); const CharacterLiteral *CL = cast<CharacterLiteral>(this);
Result.zextOrTrunc( Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
static_cast<uint32_t>(Ctx.getTypeSize(getType(), CL->getLoc())));
Result = CL->getValue(); Result = CL->getValue();
Result.setIsUnsigned(!getType()->isSignedIntegerType()); Result.setIsUnsigned(!getType()->isSignedIntegerType());
break; break;
} }
case TypesCompatibleExprClass: { case TypesCompatibleExprClass: {
const TypesCompatibleExpr *TCE = cast<TypesCompatibleExpr>(this); const TypesCompatibleExpr *TCE = cast<TypesCompatibleExpr>(this);
Result.zextOrTrunc( Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
static_cast<uint32_t>(Ctx.getTypeSize(getType(), TCE->getLocStart())));
Result = Ctx.typesAreCompatible(TCE->getArgType1(), TCE->getArgType2()); Result = Ctx.typesAreCompatible(TCE->getArgType1(), TCE->getArgType2());
break; break;
} }
case CallExprClass: { case CallExprClass: {
const CallExpr *CE = cast<CallExpr>(this); const CallExpr *CE = cast<CallExpr>(this);
Result.zextOrTrunc( Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
static_cast<uint32_t>(Ctx.getTypeSize(getType(), CE->getLocStart())));
if (CE->isBuiltinClassifyType(Result)) if (CE->isBuiltinClassifyType(Result))
break; break;
if (Loc) *Loc = getLocStart(); if (Loc) *Loc = getLocStart();
@ -723,9 +719,7 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
case UnaryOperator::SizeOf: case UnaryOperator::SizeOf:
case UnaryOperator::AlignOf: case UnaryOperator::AlignOf:
// Return the result in the right width. // Return the result in the right width.
Result.zextOrTrunc( Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
static_cast<uint32_t>(Ctx.getTypeSize(getType(),
Exp->getOperatorLoc())));
// sizeof(void) and __alignof__(void) = 1 as a gcc extension. // sizeof(void) and __alignof__(void) = 1 as a gcc extension.
if (Exp->getSubExpr()->getType()->isVoidType()) { if (Exp->getSubExpr()->getType()->isVoidType()) {
@ -744,22 +738,16 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
// GCC extension: sizeof(function) = 1. // GCC extension: sizeof(function) = 1.
Result = Exp->getOpcode() == UnaryOperator::AlignOf ? 4 : 1; Result = Exp->getOpcode() == UnaryOperator::AlignOf ? 4 : 1;
} else { } else {
unsigned CharSize = unsigned CharSize = Ctx.Target.getCharWidth();
Ctx.Target.getCharWidth(Ctx.getFullLoc(Exp->getOperatorLoc()));
if (Exp->getOpcode() == UnaryOperator::AlignOf) if (Exp->getOpcode() == UnaryOperator::AlignOf)
Result = Ctx.getTypeAlign(Exp->getSubExpr()->getType(), Result = Ctx.getTypeAlign(Exp->getSubExpr()->getType()) / CharSize;
Exp->getOperatorLoc()) / CharSize;
else else
Result = Ctx.getTypeSize(Exp->getSubExpr()->getType(), Result = Ctx.getTypeSize(Exp->getSubExpr()->getType()) / CharSize;
Exp->getOperatorLoc()) / CharSize;
} }
break; break;
case UnaryOperator::LNot: { case UnaryOperator::LNot: {
bool Val = Result == 0; bool Val = Result == 0;
Result.zextOrTrunc( Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
static_cast<uint32_t>(Ctx.getTypeSize(getType(),
Exp->getOperatorLoc())));
Result = Val; Result = Val;
break; break;
} }
@ -780,8 +768,7 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
const SizeOfAlignOfTypeExpr *Exp = cast<SizeOfAlignOfTypeExpr>(this); const SizeOfAlignOfTypeExpr *Exp = cast<SizeOfAlignOfTypeExpr>(this);
// Return the result in the right width. // Return the result in the right width.
Result.zextOrTrunc( Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
static_cast<uint32_t>(Ctx.getTypeSize(getType(), Exp->getOperatorLoc())));
// sizeof(void) and __alignof__(void) = 1 as a gcc extension. // sizeof(void) and __alignof__(void) = 1 as a gcc extension.
if (Exp->getArgumentType()->isVoidType()) { if (Exp->getArgumentType()->isVoidType()) {
@ -800,17 +787,12 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
// GCC extension: sizeof(function) = 1. // GCC extension: sizeof(function) = 1.
Result = Exp->isSizeOf() ? 1 : 4; Result = Exp->isSizeOf() ? 1 : 4;
} else { } else {
unsigned CharSize = unsigned CharSize = Ctx.Target.getCharWidth();
Ctx.Target.getCharWidth(Ctx.getFullLoc(Exp->getOperatorLoc()));
if (Exp->isSizeOf()) if (Exp->isSizeOf())
Result = Ctx.getTypeSize(Exp->getArgumentType(), Result = Ctx.getTypeSize(Exp->getArgumentType()) / CharSize;
Exp->getOperatorLoc()) / CharSize;
else else
Result = Ctx.getTypeAlign(Exp->getArgumentType(), Result = Ctx.getTypeAlign(Exp->getArgumentType()) / CharSize;
Exp->getOperatorLoc()) / CharSize;
} }
break; break;
} }
case BinaryOperatorClass: { case BinaryOperatorClass: {
@ -927,8 +909,7 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
return false; return false;
} }
uint32_t DestWidth = uint32_t DestWidth = static_cast<uint32_t>(Ctx.getTypeSize(getType()));
static_cast<uint32_t>(Ctx.getTypeSize(getType(), CastLoc));
// Handle simple integer->integer casts. // Handle simple integer->integer casts.
if (SubExpr->getType()->isIntegerType()) { if (SubExpr->getType()->isIntegerType()) {
@ -1140,7 +1121,7 @@ static int64_t evaluateOffsetOf(ASTContext& C, const Expr *E)
QualType Ty = ME->getBase()->getType(); QualType Ty = ME->getBase()->getType();
RecordDecl *RD = Ty->getAsRecordType()->getDecl(); RecordDecl *RD = Ty->getAsRecordType()->getDecl();
const ASTRecordLayout &RL = C.getASTRecordLayout(RD, SourceLocation()); const ASTRecordLayout &RL = C.getASTRecordLayout(RD);
FieldDecl *FD = ME->getMemberDecl(); FieldDecl *FD = ME->getMemberDecl();
// FIXME: This is linear time. // FIXME: This is linear time.
@ -1157,7 +1138,7 @@ static int64_t evaluateOffsetOf(ASTContext& C, const Expr *E)
bool ICE = ASE->getIdx()->isIntegerConstantExpr(Idx, C); bool ICE = ASE->getIdx()->isIntegerConstantExpr(Idx, C);
assert(ICE && "Array index is not a constant integer!"); assert(ICE && "Array index is not a constant integer!");
int64_t size = C.getTypeSize(ASE->getType(), SourceLocation()); int64_t size = C.getTypeSize(ASE->getType());
size *= Idx.getSExtValue(); size *= Idx.getSExtValue();
return size + evaluateOffsetOf(C, Base); return size + evaluateOffsetOf(C, Base);
@ -1172,9 +1153,7 @@ int64_t UnaryOperator::evaluateOffsetOf(ASTContext& C) const
{ {
assert(Opc == OffsetOf && "Unary operator not offsetof!"); assert(Opc == OffsetOf && "Unary operator not offsetof!");
unsigned CharSize = unsigned CharSize = C.Target.getCharWidth();
C.Target.getCharWidth(C.getFullLoc(getOperatorLoc()));
return ::evaluateOffsetOf(C, Val) / CharSize; return ::evaluateOffsetOf(C, Val) / CharSize;
} }

View File

@ -277,8 +277,7 @@ void GRExprEngine::ProcessSwitch(SwitchNodeBuilder& builder) {
// While most of this can be assumed (such as the signedness), having it // While most of this can be assumed (such as the signedness), having it
// just computed makes sure everything makes the same assumptions end-to-end. // just computed makes sure everything makes the same assumptions end-to-end.
unsigned bits = getContext().getTypeSize(CondE->getType(), unsigned bits = getContext().getTypeSize(CondE->getType());
CondE->getExprLoc());
APSInt V1(bits, false); APSInt V1(bits, false);
APSInt V2 = V1; APSInt V2 = V1;
@ -716,10 +715,8 @@ void GRExprEngine::VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr* Ex,
uint64_t size = 1; // Handle sizeof(void) uint64_t size = 1; // Handle sizeof(void)
if (T != getContext().VoidTy) { if (T != getContext().VoidTy)
SourceLocation Loc = Ex->getExprLoc(); size = getContext().getTypeSize(T) / 8;
size = getContext().getTypeSize(T, Loc) / 8;
}
Nodify(Dst, Ex, Pred, Nodify(Dst, Ex, Pred,
SetRVal(Pred->getState(), Ex, SetRVal(Pred->getState(), Ex,
@ -949,10 +946,9 @@ void GRExprEngine::VisitSizeOfExpr(UnaryOperator* U, NodeTy* Pred,
if (!T.getTypePtr()->isConstantSizeType()) if (!T.getTypePtr()->isConstantSizeType())
return; return;
SourceLocation Loc = U->getExprLoc(); uint64_t size = getContext().getTypeSize(T) / 8;
uint64_t size = getContext().getTypeSize(T, Loc) / 8;
ValueState* St = Pred->getState(); ValueState* St = Pred->getState();
St = SetRVal(St, U, NonLVal::MakeVal(ValMgr, size, U->getType(), Loc)); St = SetRVal(St, U, NonLVal::MakeVal(ValMgr, size, U->getType()));
Nodify(Dst, U, Pred, St); Nodify(Dst, U, Pred, St);
} }

View File

@ -160,7 +160,7 @@ RVal GRSimpleVals::EvalCast(ValueManager& ValMgr, NonLVal X, QualType T) {
llvm::APSInt V = cast<nonlval::ConcreteInt>(X).getValue(); llvm::APSInt V = cast<nonlval::ConcreteInt>(X).getValue();
V.setIsUnsigned(T->isUnsignedIntegerType() || T->isPointerType()); V.setIsUnsigned(T->isUnsignedIntegerType() || T->isPointerType());
V.extOrTrunc(ValMgr.getContext().getTypeSize(T, SourceLocation())); V.extOrTrunc(ValMgr.getContext().getTypeSize(T));
if (T->isPointerType()) if (T->isPointerType())
return lval::ConcreteInt(ValMgr.getValue(V)); return lval::ConcreteInt(ValMgr.getValue(V));
@ -182,7 +182,7 @@ RVal GRSimpleVals::EvalCast(ValueManager& ValMgr, LVal X, QualType T) {
llvm::APSInt V = cast<lval::ConcreteInt>(X).getValue(); llvm::APSInt V = cast<lval::ConcreteInt>(X).getValue();
V.setIsUnsigned(T->isUnsignedIntegerType() || T->isPointerType()); V.setIsUnsigned(T->isUnsignedIntegerType() || T->isPointerType());
V.extOrTrunc(ValMgr.getContext().getTypeSize(T, SourceLocation())); V.extOrTrunc(ValMgr.getContext().getTypeSize(T));
return nonlval::ConcreteInt(ValMgr.getValue(V)); return nonlval::ConcreteInt(ValMgr.getValue(V));
} }

View File

@ -207,10 +207,8 @@ NonLVal LVal::NE(ValueManager& ValMgr, const LVal& R) const {
// Utility methods for constructing Non-LVals. // Utility methods for constructing Non-LVals.
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
NonLVal NonLVal::MakeVal(ValueManager& ValMgr, uint64_t X, QualType T, NonLVal NonLVal::MakeVal(ValueManager& ValMgr, uint64_t X, QualType T) {
SourceLocation Loc) { return nonlval::ConcreteInt(ValMgr.getValue(X, T));
return nonlval::ConcreteInt(ValMgr.getValue(X, T, Loc));
} }
NonLVal NonLVal::MakeVal(ValueManager& ValMgr, IntegerLiteral* I) { NonLVal NonLVal::MakeVal(ValueManager& ValMgr, IntegerLiteral* I) {
@ -220,7 +218,6 @@ NonLVal NonLVal::MakeVal(ValueManager& ValMgr, IntegerLiteral* I) {
} }
NonLVal NonLVal::MakeIntTruthVal(ValueManager& ValMgr, bool b) { NonLVal NonLVal::MakeIntTruthVal(ValueManager& ValMgr, bool b) {
return nonlval::ConcreteInt(ValMgr.getTruthValue(b)); return nonlval::ConcreteInt(ValMgr.getTruthValue(b));
} }

View File

@ -48,10 +48,9 @@ const llvm::APSInt& ValueManager::getValue(uint64_t X, unsigned BitWidth,
return getValue(V); return getValue(V);
} }
const llvm::APSInt& ValueManager::getValue(uint64_t X, QualType T, const llvm::APSInt& ValueManager::getValue(uint64_t X, QualType T) {
SourceLocation Loc) {
unsigned bits = Ctx.getTypeSize(T, Loc); unsigned bits = Ctx.getTypeSize(T);
llvm::APSInt V(bits, T->isUnsignedIntegerType()); llvm::APSInt V(bits, T->isUnsignedIntegerType());
V = X; V = X;
return getValue(V); return getValue(V);

View File

@ -258,8 +258,7 @@ RVal ValueStateManager::GetRVal(ValueState* St, Expr* E) {
case Stmt::CharacterLiteralClass: { case Stmt::CharacterLiteralClass: {
CharacterLiteral* C = cast<CharacterLiteral>(E); CharacterLiteral* C = cast<CharacterLiteral>(E);
return NonLVal::MakeVal(ValMgr, C->getValue(), C->getType(), return NonLVal::MakeVal(ValMgr, C->getValue(), C->getType());
C->getLoc());
} }
case Stmt::IntegerLiteralClass: { case Stmt::IntegerLiteralClass: {
@ -271,7 +270,6 @@ RVal ValueStateManager::GetRVal(ValueState* St, Expr* E) {
// subexpression that has a value. // subexpression that has a value.
case Stmt::ImplicitCastExprClass: { case Stmt::ImplicitCastExprClass: {
ImplicitCastExpr* C = cast<ImplicitCastExpr>(E); ImplicitCastExpr* C = cast<ImplicitCastExpr>(E);
QualType CT = C->getType(); QualType CT = C->getType();
@ -341,8 +339,7 @@ RVal ValueStateManager::GetBlkExprRVal(ValueState* St, Expr* E) {
switch (E->getStmtClass()) { switch (E->getStmtClass()) {
case Stmt::CharacterLiteralClass: { case Stmt::CharacterLiteralClass: {
CharacterLiteral* C = cast<CharacterLiteral>(E); CharacterLiteral* C = cast<CharacterLiteral>(E);
return NonLVal::MakeVal(ValMgr, C->getValue(), C->getType(), return NonLVal::MakeVal(ValMgr, C->getValue(), C->getType());
C->getLoc());
} }
case Stmt::IntegerLiteralClass: { case Stmt::IntegerLiteralClass: {

View File

@ -28,22 +28,19 @@ void TargetInfoImpl::ANCHOR() {} // out-of-line virtual method for class.
// TargetInfoImpl. // TargetInfoImpl.
void TargetInfo::getFloatInfo(uint64_t &Size, unsigned &Align, void TargetInfo::getFloatInfo(uint64_t &Size, unsigned &Align,
const llvm::fltSemantics *&Format, const llvm::fltSemantics *&Format) {
FullSourceLoc Loc) {
Align = 32; // FIXME: implement correctly. Align = 32; // FIXME: implement correctly.
Size = 32; Size = 32;
Format = &llvm::APFloat::IEEEsingle; Format = &llvm::APFloat::IEEEsingle;
} }
void TargetInfo::getDoubleInfo(uint64_t &Size, unsigned &Align, void TargetInfo::getDoubleInfo(uint64_t &Size, unsigned &Align,
const llvm::fltSemantics *&Format, const llvm::fltSemantics *&Format) {
FullSourceLoc Loc) {
Size = 64; // FIXME: implement correctly. Size = 64; // FIXME: implement correctly.
Align = 32; Align = 32;
Format = &llvm::APFloat::IEEEdouble; Format = &llvm::APFloat::IEEEdouble;
} }
void TargetInfo::getLongDoubleInfo(uint64_t &Size, unsigned &Align, void TargetInfo::getLongDoubleInfo(uint64_t &Size, unsigned &Align,
const llvm::fltSemantics *&Format, const llvm::fltSemantics *&Format) {
FullSourceLoc Loc) {
Size = Align = 64; // FIXME: implement correctly. Size = Align = 64; // FIXME: implement correctly.
Format = &llvm::APFloat::IEEEdouble; Format = &llvm::APFloat::IEEEdouble;
//Size = 80; Align = 32; // FIXME: implement correctly. //Size = 80; Align = 32; // FIXME: implement correctly.
@ -74,7 +71,7 @@ void TargetInfo::getTargetDefines(std::vector<char> &Buffer) {
/// ComputeWCharWidth - Determine the width of the wchar_t type for the primary /// ComputeWCharWidth - Determine the width of the wchar_t type for the primary
/// target, diagnosing whether this is non-portable across the secondary /// target, diagnosing whether this is non-portable across the secondary
/// targets. /// targets.
void TargetInfo::ComputeWCharInfo(FullSourceLoc Loc) { void TargetInfo::ComputeWCharInfo() {
Target->getWCharInfo(WCharWidth, WCharAlign); Target->getWCharInfo(WCharWidth, WCharAlign);
} }

View File

@ -722,50 +722,6 @@ public:
} // end anonymous namespace. } // end anonymous namespace.
namespace {
class LinuxTargetInfo : public DarwinTargetInfo {
public:
LinuxTargetInfo(const std::string& triple) : DarwinTargetInfo(triple) {
// Note: I have no idea if this is right, just for testing.
WCharWidth = 16;
WCharAlign = 16;
}
virtual void getTargetDefines(std::vector<char> &Defines) const {
// TODO: linux-specific stuff.
getX86Defines(Defines, false);
}
virtual void getTargetBuiltins(const Builtin::Info *&Records,
unsigned &NumRecords) const {
X86::getBuiltins(Records, NumRecords);
}
virtual const char *getVAListDeclaration() const {
return getI386VAListDeclaration();
}
virtual const char *getTargetPrefix() const {
return X86::getTargetPrefix();
}
virtual void getGCCRegNames(const char * const *&Names,
unsigned &NumNames) const {
X86::getGCCRegNames(Names, NumNames);
}
virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
unsigned &NumAliases) const {
X86::getGCCRegAliases(Aliases, NumAliases);
}
virtual bool validateAsmConstraint(char c,
TargetInfo::ConstraintInfo &info) const {
return X86::validateAsmConstraint(c, info);
}
virtual std::string convertConstraint(const char Constraint) const {
return X86::convertConstraint(Constraint);
}
virtual const char *getClobbers() const {
return X86::getClobbers();
}
};
} // end anonymous namespace.
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Driver code // Driver code
@ -794,9 +750,6 @@ TargetInfo* TargetInfo::CreateTargetInfo(const std::string &T) {
if (IsX86(T)) if (IsX86(T))
return new TargetInfo(new DarwinI386TargetInfo(T)); return new TargetInfo(new DarwinI386TargetInfo(T));
if (T.find("bogusW16W16-") == 0) // For testing portability.
return new TargetInfo(new LinuxTargetInfo(T));
return NULL; return NULL;
} }

View File

@ -103,8 +103,7 @@ void AggExprEmitter::EmitAggregateClear(llvm::Value *DestPtr, QualType Ty) {
DestPtr = Builder.CreateBitCast(DestPtr, BP, "tmp"); DestPtr = Builder.CreateBitCast(DestPtr, BP, "tmp");
// Get size and alignment info for this aggregate. // Get size and alignment info for this aggregate.
std::pair<uint64_t, unsigned> TypeInfo = std::pair<uint64_t, unsigned> TypeInfo = CGF.getContext().getTypeInfo(Ty);
CGF.getContext().getTypeInfo(Ty, SourceLocation());
// FIXME: Handle variable sized types. // FIXME: Handle variable sized types.
const llvm::Type *IntPtr = llvm::IntegerType::get(CGF.LLVMPointerWidth); const llvm::Type *IntPtr = llvm::IntegerType::get(CGF.LLVMPointerWidth);
@ -132,8 +131,7 @@ void AggExprEmitter::EmitAggregateCopy(llvm::Value *DestPtr,
SrcPtr = Builder.CreateBitCast(SrcPtr, BP, "tmp"); SrcPtr = Builder.CreateBitCast(SrcPtr, BP, "tmp");
// Get size and alignment info for this aggregate. // Get size and alignment info for this aggregate.
std::pair<uint64_t, unsigned> TypeInfo = std::pair<uint64_t, unsigned> TypeInfo = CGF.getContext().getTypeInfo(Ty);
CGF.getContext().getTypeInfo(Ty, SourceLocation());
// FIXME: Handle variable sized types. // FIXME: Handle variable sized types.
const llvm::Type *IntPtr = llvm::IntegerType::get(CGF.LLVMPointerWidth); const llvm::Type *IntPtr = llvm::IntegerType::get(CGF.LLVMPointerWidth);

View File

@ -37,7 +37,8 @@ public:
llvm::Constant *VisitStmt(Stmt *S) { llvm::Constant *VisitStmt(Stmt *S) {
CGM.WarnUnsupported(S, "constant expression"); CGM.WarnUnsupported(S, "constant expression");
return llvm::UndefValue::get(CGM.getTypes().ConvertType(cast<Expr>(S)->getType())); QualType T = cast<Expr>(S)->getType();
return llvm::UndefValue::get(CGM.getTypes().ConvertType(T));
} }
llvm::Constant *VisitParenExpr(ParenExpr *PE) { llvm::Constant *VisitParenExpr(ParenExpr *PE) {
@ -314,8 +315,8 @@ public:
assert(E->getType()->isIntegerType() && "Result type must be an integer!"); assert(E->getType()->isIntegerType() && "Result type must be an integer!");
uint32_t ResultWidth = static_cast<uint32_t>( uint32_t ResultWidth =
CGM.getContext().getTypeSize(E->getType(), SourceLocation())); static_cast<uint32_t>(CGM.getContext().getTypeSize(E->getType()));
return llvm::ConstantInt::get(llvm::APInt(ResultWidth, Val)); return llvm::ConstantInt::get(llvm::APInt(ResultWidth, Val));
} }
@ -504,15 +505,15 @@ public:
llvm::Constant *EmitSizeAlignOf(QualType TypeToSize, llvm::Constant *EmitSizeAlignOf(QualType TypeToSize,
QualType RetType, bool isSizeOf) { QualType RetType, bool isSizeOf) {
std::pair<uint64_t, unsigned> Info = std::pair<uint64_t, unsigned> Info =
CGM.getContext().getTypeInfo(TypeToSize, SourceLocation()); CGM.getContext().getTypeInfo(TypeToSize);
uint64_t Val = isSizeOf ? Info.first : Info.second; uint64_t Val = isSizeOf ? Info.first : Info.second;
Val /= 8; // Return size in bytes, not bits. Val /= 8; // Return size in bytes, not bits.
assert(RetType->isIntegerType() && "Result type must be an integer!"); assert(RetType->isIntegerType() && "Result type must be an integer!");
uint32_t ResultWidth = static_cast<uint32_t>( uint32_t ResultWidth =
CGM.getContext().getTypeSize(RetType, SourceLocation())); static_cast<uint32_t>(CGM.getContext().getTypeSize(RetType));
return llvm::ConstantInt::get(llvm::APInt(ResultWidth, Val)); return llvm::ConstantInt::get(llvm::APInt(ResultWidth, Val));
} }
@ -616,8 +617,7 @@ llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E,
QualType type = E->getType().getCanonicalType(); QualType type = E->getType().getCanonicalType();
if (type->isIntegerType()) { if (type->isIntegerType()) {
llvm::APSInt llvm::APSInt Value(static_cast<uint32_t>(Context.getTypeSize(type)));
Value(static_cast<uint32_t>(Context.getTypeSize(type, SourceLocation())));
if (E->isIntegerConstantExpr(Value, Context)) { if (E->isIntegerConstantExpr(Value, Context)) {
return llvm::ConstantInt::get(Value); return llvm::ConstantInt::get(Value);
} }

View File

@ -656,16 +656,14 @@ Value *ScalarExprEmitter::EmitSizeAlignOf(QualType TypeToSize,
QualType RetType,bool isSizeOf){ QualType RetType,bool isSizeOf){
assert(RetType->isIntegerType() && "Result type must be an integer!"); assert(RetType->isIntegerType() && "Result type must be an integer!");
uint32_t ResultWidth = uint32_t ResultWidth =
static_cast<uint32_t>(CGF.getContext().getTypeSize(RetType, static_cast<uint32_t>(CGF.getContext().getTypeSize(RetType));
SourceLocation()));
// sizeof(void) and __alignof__(void) = 1 as a gcc extension. // sizeof(void) and __alignof__(void) = 1 as a gcc extension.
if (TypeToSize->isVoidType()) if (TypeToSize->isVoidType())
return llvm::ConstantInt::get(llvm::APInt(ResultWidth, 1)); return llvm::ConstantInt::get(llvm::APInt(ResultWidth, 1));
/// FIXME: This doesn't handle VLAs yet! /// FIXME: This doesn't handle VLAs yet!
std::pair<uint64_t, unsigned> Info = std::pair<uint64_t, unsigned> Info = CGF.getContext().getTypeInfo(TypeToSize);
CGF.getContext().getTypeInfo(TypeToSize, SourceLocation());
uint64_t Val = isSizeOf ? Info.first : Info.second; uint64_t Val = isSizeOf ? Info.first : Info.second;
Val /= 8; // Return size in bytes, not bits. Val /= 8; // Return size in bytes, not bits.
@ -696,8 +694,8 @@ Value *ScalarExprEmitter::VisitUnaryOffsetOf(const UnaryOperator *E)
assert(E->getType()->isIntegerType() && "Result type must be an integer!"); assert(E->getType()->isIntegerType() && "Result type must be an integer!");
uint32_t ResultWidth = static_cast<uint32_t>( uint32_t ResultWidth =
CGF.getContext().getTypeSize(E->getType(), SourceLocation())); static_cast<uint32_t>(CGF.getContext().getTypeSize(E->getType()));
return llvm::ConstantInt::get(llvm::APInt(ResultWidth, Val)); return llvm::ConstantInt::get(llvm::APInt(ResultWidth, Val));
} }
@ -852,8 +850,7 @@ Value *ScalarExprEmitter::VisitBinSub(const BinaryOperator *E) {
const QualType LHSType = E->getLHS()->getType().getCanonicalType(); const QualType LHSType = E->getLHS()->getType().getCanonicalType();
const QualType LHSElementType = cast<PointerType>(LHSType)->getPointeeType(); const QualType LHSElementType = cast<PointerType>(LHSType)->getPointeeType();
uint64_t ElementSize = CGF.getContext().getTypeSize(LHSElementType, uint64_t ElementSize = CGF.getContext().getTypeSize(LHSElementType) / 8;
SourceLocation()) / 8;
const llvm::Type *ResultType = ConvertType(E->getType()); const llvm::Type *ResultType = ConvertType(E->getType());
LHS = Builder.CreatePtrToInt(LHS, ResultType, "sub.ptr.lhs.cast"); LHS = Builder.CreatePtrToInt(LHS, ResultType, "sub.ptr.lhs.cast");

View File

@ -59,8 +59,7 @@ bool CodeGenFunction::hasAggregateLLVMType(QualType T) {
void CodeGenFunction::GenerateCode(const FunctionDecl *FD) { void CodeGenFunction::GenerateCode(const FunctionDecl *FD) {
LLVMIntTy = ConvertType(getContext().IntTy); LLVMIntTy = ConvertType(getContext().IntTy);
LLVMPointerWidth = static_cast<unsigned>( LLVMPointerWidth = static_cast<unsigned>(
getContext().getTypeSize(getContext().getPointerType(getContext().VoidTy), getContext().getTypeSize(getContext().getPointerType(getContext().VoidTy)));
SourceLocation()));
CurFuncDecl = FD; CurFuncDecl = FD;
CurFn = cast<llvm::Function>(CGM.GetAddrOfFunctionDecl(FD, true)); CurFn = cast<llvm::Function>(CGM.GetAddrOfFunctionDecl(FD, true));

View File

@ -231,7 +231,7 @@ void CodeGenModule::EmitGlobalVar(const FileVarDecl *D) {
Init = llvm::Constant::getNullValue(GV->getType()->getElementType()); Init = llvm::Constant::getNullValue(GV->getType()->getElementType());
} else if (D->getType()->isIntegerType()) { } else if (D->getType()->isIntegerType()) {
llvm::APSInt Value(static_cast<uint32_t>( llvm::APSInt Value(static_cast<uint32_t>(
getContext().getTypeSize(D->getInit()->getType(), SourceLocation()))); getContext().getTypeSize(D->getInit()->getType())));
if (D->getInit()->isIntegerConstantExpr(Value, Context)) if (D->getInit()->isIntegerConstantExpr(Value, Context))
Init = llvm::ConstantInt::get(Value); Init = llvm::ConstantInt::get(Value);
} }
@ -340,7 +340,7 @@ llvm::Function *CodeGenModule::getMemCpyFn() {
if (MemCpyFn) return MemCpyFn; if (MemCpyFn) return MemCpyFn;
llvm::Intrinsic::ID IID; llvm::Intrinsic::ID IID;
uint64_t Size; unsigned Align; uint64_t Size; unsigned Align;
Context.Target.getPointerInfo(Size, Align, FullSourceLoc()); Context.Target.getPointerInfo(Size, Align);
switch (Size) { switch (Size) {
default: assert(0 && "Unknown ptr width"); default: assert(0 && "Unknown ptr width");
case 32: IID = llvm::Intrinsic::memcpy_i32; break; case 32: IID = llvm::Intrinsic::memcpy_i32; break;
@ -353,7 +353,7 @@ llvm::Function *CodeGenModule::getMemSetFn() {
if (MemSetFn) return MemSetFn; if (MemSetFn) return MemSetFn;
llvm::Intrinsic::ID IID; llvm::Intrinsic::ID IID;
uint64_t Size; unsigned Align; uint64_t Size; unsigned Align;
Context.Target.getPointerInfo(Size, Align, FullSourceLoc()); Context.Target.getPointerInfo(Size, Align);
switch (Size) { switch (Size) {
default: assert(0 && "Unknown ptr width"); default: assert(0 && "Unknown ptr width");
case 32: IID = llvm::Intrinsic::memset_i32; break; case 32: IID = llvm::Intrinsic::memset_i32; break;

View File

@ -118,8 +118,7 @@ const llvm::Type *CodeGenTypes::ConvertTypeForMem(QualType T) {
return R; return R;
// Otherwise, return an integer of the target-specified size. // Otherwise, return an integer of the target-specified size.
unsigned BoolWidth = (unsigned)Context.getTypeSize(T, SourceLocation()); return llvm::IntegerType::get((unsigned)Context.getTypeSize(T));
return llvm::IntegerType::get(BoolWidth);
} }
@ -179,7 +178,7 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) {
case BuiltinType::LongLong: case BuiltinType::LongLong:
case BuiltinType::ULongLong: case BuiltinType::ULongLong:
return llvm::IntegerType::get( return llvm::IntegerType::get(
static_cast<unsigned>(Context.getTypeSize(T, SourceLocation()))); static_cast<unsigned>(Context.getTypeSize(T)));
case BuiltinType::Float: return llvm::Type::FloatTy; case BuiltinType::Float: return llvm::Type::FloatTy;
case BuiltinType::Double: return llvm::Type::DoubleTy; case BuiltinType::Double: return llvm::Type::DoubleTy;
@ -356,7 +355,7 @@ const llvm::Type *CodeGenTypes::ConvertTagDeclType(const TagDecl *TD) {
for (unsigned i = 0, e = RD->getNumMembers(); i != e; ++i) for (unsigned i = 0, e = RD->getNumMembers(); i != e; ++i)
RO.addField(RD->getMember(i)); RO.addField(RD->getMember(i));
RO.layoutStructFields(Context.getASTRecordLayout(RD, SourceLocation())); RO.layoutStructFields(Context.getASTRecordLayout(RD));
// Get llvm::StructType. // Get llvm::StructType.
CGRecordLayouts[TD] = new CGRecordLayout(RO.getLLVMType(), CGRecordLayouts[TD] = new CGRecordLayout(RO.getLLVMType(),
@ -514,7 +513,7 @@ void RecordOrganizer::layoutUnionFields() {
unsigned PrimaryEltNo = 0; unsigned PrimaryEltNo = 0;
std::pair<uint64_t, unsigned> PrimaryElt = std::pair<uint64_t, unsigned> PrimaryElt =
CGT.getContext().getTypeInfo(FieldDecls[0]->getType(), SourceLocation()); CGT.getContext().getTypeInfo(FieldDecls[0]->getType());
CGT.addFieldInfo(FieldDecls[0], 0); CGT.addFieldInfo(FieldDecls[0], 0);
unsigned Size = FieldDecls.size(); unsigned Size = FieldDecls.size();
@ -522,7 +521,7 @@ void RecordOrganizer::layoutUnionFields() {
const FieldDecl *FD = FieldDecls[i]; const FieldDecl *FD = FieldDecls[i];
assert (!FD->isBitField() && "Bit fields are not yet supported"); assert (!FD->isBitField() && "Bit fields are not yet supported");
std::pair<uint64_t, unsigned> EltInfo = std::pair<uint64_t, unsigned> EltInfo =
CGT.getContext().getTypeInfo(FD->getType(), SourceLocation()); CGT.getContext().getTypeInfo(FD->getType());
// Use largest element, breaking ties with the hightest aligned member. // Use largest element, breaking ties with the hightest aligned member.
if (EltInfo.first > PrimaryElt.first || if (EltInfo.first > PrimaryElt.first ||

View File

@ -2037,9 +2037,8 @@ Stmt *RewriteTest::SynthMessageExpr(ObjCMessageExpr *Exp) {
// FIXME: Value of 8 is base on ppc32/x86 ABI for the most common cases. // FIXME: Value of 8 is base on ppc32/x86 ABI for the most common cases.
// For X86 it is more complicated and some kind of target specific routine // For X86 it is more complicated and some kind of target specific routine
// is needed to decide what to do. // is needed to decide what to do.
unsigned IntSize = static_cast<unsigned>( unsigned IntSize =
Context->getTypeSize(Context->IntTy, SourceLocation())); static_cast<unsigned>(Context->getTypeSize(Context->IntTy));
IntegerLiteral *limit = new IntegerLiteral(llvm::APInt(IntSize, 8), IntegerLiteral *limit = new IntegerLiteral(llvm::APInt(IntSize, 8),
Context->IntTy, Context->IntTy,
SourceLocation()); SourceLocation());

View File

@ -93,9 +93,7 @@ static unsigned ProcessCharEscape(const char *&ThisTokBuf,
} }
// See if any bits will be truncated when evaluated as a character. // See if any bits will be truncated when evaluated as a character.
unsigned CharWidth = IsWide unsigned CharWidth = PP.getTargetInfo().getCharWidth(IsWide);
? PP.getTargetInfo().getWCharWidth(PP.getFullLoc(Loc))
: PP.getTargetInfo().getCharWidth(PP.getFullLoc(Loc));
if (CharWidth != 32 && (ResultChar >> CharWidth) != 0) { if (CharWidth != 32 && (ResultChar >> CharWidth) != 0) {
Overflow = true; Overflow = true;
@ -124,9 +122,7 @@ static unsigned ProcessCharEscape(const char *&ThisTokBuf,
ThisTokBuf[0] >= '0' && ThisTokBuf[0] <= '7'); ThisTokBuf[0] >= '0' && ThisTokBuf[0] <= '7');
// Check for overflow. Reject '\777', but not L'\777'. // Check for overflow. Reject '\777', but not L'\777'.
unsigned CharWidth = IsWide unsigned CharWidth = PP.getTargetInfo().getCharWidth(IsWide);
? PP.getTargetInfo().getWCharWidth(PP.getFullLoc(Loc))
: PP.getTargetInfo().getCharWidth(PP.getFullLoc(Loc));
if (CharWidth != 32 && (ResultChar >> CharWidth) != 0) { if (CharWidth != 32 && (ResultChar >> CharWidth) != 0) {
PP.Diag(Loc, diag::warn_octal_escape_too_large); PP.Diag(Loc, diag::warn_octal_escape_too_large);
@ -457,13 +453,13 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end,
// FIXME: This assumes that 'int' is 32-bits in overflow calculation, and the // FIXME: This assumes that 'int' is 32-bits in overflow calculation, and the
// size of "value". // size of "value".
assert(PP.getTargetInfo().getIntWidth(PP.getFullLoc(Loc)) == 32 && assert(PP.getTargetInfo().getIntWidth() == 32 &&
"Assumes sizeof(int) == 4 for now"); "Assumes sizeof(int) == 4 for now");
// FIXME: This assumes that wchar_t is 32-bits for now. // FIXME: This assumes that wchar_t is 32-bits for now.
assert(PP.getTargetInfo().getWCharWidth(PP.getFullLoc(Loc)) == 32 && assert(PP.getTargetInfo().getWCharWidth() == 32 &&
"Assumes sizeof(wchar_t) == 4 for now"); "Assumes sizeof(wchar_t) == 4 for now");
// FIXME: This extensively assumes that 'char' is 8-bits. // FIXME: This extensively assumes that 'char' is 8-bits.
assert(PP.getTargetInfo().getCharWidth(PP.getFullLoc(Loc)) == 8 && assert(PP.getTargetInfo().getCharWidth() == 8 &&
"Assumes char is 8 bits"); "Assumes char is 8 bits");
bool isFirstChar = true; bool isFirstChar = true;
@ -509,7 +505,7 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end,
// character constants are not sign extended in the this implementation: // character constants are not sign extended in the this implementation:
// '\xFF\xFF' = 65536 and '\x0\xFF' = 255, which matches GCC. // '\xFF\xFF' = 65536 and '\x0\xFF' = 255, which matches GCC.
if (!IsWide && !isMultiChar && (Value & 128) && if (!IsWide && !isMultiChar && (Value & 128) &&
PP.getTargetInfo().isCharSigned(PP.getFullLoc(Loc))) PP.getTargetInfo().isCharSigned())
Value = (signed char)Value; Value = (signed char)Value;
} }
@ -587,9 +583,7 @@ StringLiteralParser(const Token *StringToks, unsigned NumStringToks,
// query the target. As such, wchar_tByteWidth is only valid if AnyWide=true. // query the target. As such, wchar_tByteWidth is only valid if AnyWide=true.
wchar_tByteWidth = ~0U; wchar_tByteWidth = ~0U;
if (AnyWide) { if (AnyWide) {
wchar_tByteWidth = wchar_tByteWidth = Target.getWCharWidth();
Target.getWCharWidth(PP.getFullLoc(StringToks[0].getLocation()));
assert((wchar_tByteWidth & 7) == 0 && "Assumes wchar_t is byte multiple!"); assert((wchar_tByteWidth & 7) == 0 && "Assumes wchar_t is byte multiple!");
wchar_tByteWidth /= 8; wchar_tByteWidth /= 8;
} }

View File

@ -195,25 +195,17 @@ static bool EvaluateValue(llvm::APSInt &Result, Token &PeekTok,
// Character literals are always int or wchar_t, expand to intmax_t. // Character literals are always int or wchar_t, expand to intmax_t.
TargetInfo &TI = PP.getTargetInfo(); TargetInfo &TI = PP.getTargetInfo();
unsigned NumBits; unsigned NumBits = TI.getCharWidth(Literal.isWide());
if (Literal.isWide())
NumBits = TI.getWCharWidth(PP.getFullLoc(PeekTok.getLocation()));
else
NumBits = TI.getCharWidth(PP.getFullLoc(PeekTok.getLocation()));
// Set the width. // Set the width.
llvm::APSInt Val(NumBits); llvm::APSInt Val(NumBits);
// Set the value. // Set the value.
Val = Literal.getValue(); Val = Literal.getValue();
// Set the signedness. // Set the signedness.
Val.setIsUnsigned(!TI.isCharSigned(PP.getFullLoc(PeekTok.getLocation()))); Val.setIsUnsigned(!TI.isCharSigned());
if (Result.getBitWidth() > Val.getBitWidth()) { if (Result.getBitWidth() > Val.getBitWidth()) {
if (Val.isSigned()) Result = Val.extend(Result.getBitWidth());
Result = Val.sext(Result.getBitWidth());
else
Result = Val.zext(Result.getBitWidth());
Result.setIsUnsigned(Val.isUnsigned());
} else { } else {
assert(Result.getBitWidth() == Val.getBitWidth() && assert(Result.getBitWidth() == Val.getBitWidth() &&
"intmax_t smaller than char/wchar_t?"); "intmax_t smaller than char/wchar_t?");
@ -603,8 +595,7 @@ EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro) {
Lex(Tok); Lex(Tok);
// C99 6.10.1p3 - All expressions are evaluated as intmax_t or uintmax_t. // C99 6.10.1p3 - All expressions are evaluated as intmax_t or uintmax_t.
unsigned BitWidth = unsigned BitWidth = getTargetInfo().getIntMaxTWidth();
getTargetInfo().getIntMaxTWidth(getFullLoc(Tok.getLocation()));
llvm::APSInt ResVal(BitWidth); llvm::APSInt ResVal(BitWidth);
DefinedTracker DT; DefinedTracker DT;

View File

@ -1561,8 +1561,7 @@ Sema::DeclTy *Sema::ActOnEnumConstant(Scope *S, DeclTy *theEnumDecl,
} else { } else {
// First value, set to zero. // First value, set to zero.
EltTy = Context.IntTy; EltTy = Context.IntTy;
EnumVal.zextOrTrunc( EnumVal.zextOrTrunc(static_cast<uint32_t>(Context.getTypeSize(EltTy)));
static_cast<uint32_t>(Context.getTypeSize(EltTy, IdLoc)));
} }
} }
@ -1584,9 +1583,7 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX,
// TODO: If the result value doesn't fit in an int, it must be a long or long // TODO: If the result value doesn't fit in an int, it must be a long or long
// long value. ISO C does not support this, but GCC does as an extension, // long value. ISO C does not support this, but GCC does as an extension,
// emit a warning. // emit a warning.
unsigned IntWidth = unsigned IntWidth = Context.Target.getIntWidth();
Context.Target.getIntWidth(Context.getFullLoc(Enum->getLocation()));
// Verify that all the values are okay, compute the size of the values, and // Verify that all the values are okay, compute the size of the values, and
// reverse the list. // reverse the list.
@ -1643,14 +1640,12 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX,
BestType = Context.IntTy; BestType = Context.IntTy;
BestWidth = IntWidth; BestWidth = IntWidth;
} else { } else {
BestWidth = BestWidth = Context.Target.getLongWidth();
Context.Target.getLongWidth(Context.getFullLoc(Enum->getLocation()));
if (NumNegativeBits <= BestWidth && NumPositiveBits < BestWidth) if (NumNegativeBits <= BestWidth && NumPositiveBits < BestWidth)
BestType = Context.LongTy; BestType = Context.LongTy;
else { else {
BestWidth = Context.Target.getLongLongWidth( BestWidth = Context.Target.getLongLongWidth();
Context.getFullLoc(Enum->getLocation()));
if (NumNegativeBits > BestWidth || NumPositiveBits >= BestWidth) if (NumNegativeBits > BestWidth || NumPositiveBits >= BestWidth)
Diag(Enum->getLocation(), diag::warn_enum_too_large); Diag(Enum->getLocation(), diag::warn_enum_too_large);
@ -1664,14 +1659,10 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX,
BestType = Context.UnsignedIntTy; BestType = Context.UnsignedIntTy;
BestWidth = IntWidth; BestWidth = IntWidth;
} else if (NumPositiveBits <= } else if (NumPositiveBits <=
(BestWidth = Context.Target.getLongWidth( (BestWidth = Context.Target.getLongWidth())) {
Context.getFullLoc(Enum->getLocation()))))
BestType = Context.UnsignedLongTy; BestType = Context.UnsignedLongTy;
else { } else {
BestWidth = BestWidth = Context.Target.getLongLongWidth();
Context.Target.getLongLongWidth(Context.getFullLoc(Enum->getLocation()));
assert(NumPositiveBits <= BestWidth && assert(NumPositiveBits <= BestWidth &&
"How could an initializer get larger than ULL?"); "How could an initializer get larger than ULL?");
BestType = Context.UnsignedLongLongTy; BestType = Context.UnsignedLongLongTy;
@ -1936,8 +1927,7 @@ QualType Sema::HandleVectorTypeAttribute(QualType curType,
curType.getCanonicalType().getAsString()); curType.getCanonicalType().getAsString());
return QualType(); return QualType();
} }
unsigned typeSize = static_cast<unsigned>( unsigned typeSize = static_cast<unsigned>(Context.getTypeSize(curType));
Context.getTypeSize(curType, rawAttr->getLoc()));
// vecSize is specified in bytes - convert to bits. // vecSize is specified in bytes - convert to bits.
unsigned vectorSize = static_cast<unsigned>(vecSize.getZExtValue() * 8); unsigned vectorSize = static_cast<unsigned>(vecSize.getZExtValue() * 8);
@ -1970,7 +1960,7 @@ void Sema::HandlePackedAttribute(Decl *d, AttributeList *rawAttr) {
else if (FieldDecl *FD = dyn_cast<FieldDecl>(d)) { else if (FieldDecl *FD = dyn_cast<FieldDecl>(d)) {
// If the alignment is less than or equal to 8 bits, the packed attribute // If the alignment is less than or equal to 8 bits, the packed attribute
// has no effect. // has no effect.
if (Context.getTypeAlign(FD->getType(), SourceLocation()) <= 8) if (Context.getTypeAlign(FD->getType()) <= 8)
Diag(rawAttr->getLoc(), Diag(rawAttr->getLoc(),
diag::warn_attribute_ignored_for_field_of_type, diag::warn_attribute_ignored_for_field_of_type,
rawAttr->getName()->getName(), FD->getType().getAsString()); rawAttr->getName()->getName(), FD->getType().getAsString());

View File

@ -169,8 +169,7 @@ Action::ExprResult Sema::ActOnNumericConstant(const Token &Tok) {
if (Tok.getLength() == 1) { if (Tok.getLength() == 1) {
const char *t = PP.getSourceManager().getCharacterData(Tok.getLocation()); const char *t = PP.getSourceManager().getCharacterData(Tok.getLocation());
unsigned IntSize = static_cast<unsigned>( unsigned IntSize =static_cast<unsigned>(Context.getTypeSize(Context.IntTy));
Context.getTypeSize(Context.IntTy, Tok.getLocation()));
return ExprResult(new IntegerLiteral(llvm::APInt(IntSize, *t-'0'), return ExprResult(new IntegerLiteral(llvm::APInt(IntSize, *t-'0'),
Context.IntTy, Context.IntTy,
Tok.getLocation())); Tok.getLocation()));
@ -195,17 +194,13 @@ Action::ExprResult Sema::ActOnNumericConstant(const Token &Tok) {
if (Literal.isFloat) { if (Literal.isFloat) {
Ty = Context.FloatTy; Ty = Context.FloatTy;
Context.Target.getFloatInfo(Size, Align, Format, Context.Target.getFloatInfo(Size, Align, Format);
Context.getFullLoc(Tok.getLocation()));
} else if (Literal.isLong) { } else if (Literal.isLong) {
Ty = Context.LongDoubleTy; Ty = Context.LongDoubleTy;
Context.Target.getLongDoubleInfo(Size, Align, Format, Context.Target.getLongDoubleInfo(Size, Align, Format);
Context.getFullLoc(Tok.getLocation()));
} else { } else {
Ty = Context.DoubleTy; Ty = Context.DoubleTy;
Context.Target.getDoubleInfo(Size, Align, Format, Context.Target.getDoubleInfo(Size, Align, Format);
Context.getFullLoc(Tok.getLocation()));
} }
// isExact will be set by GetFloatValue(). // isExact will be set by GetFloatValue().
@ -225,15 +220,14 @@ Action::ExprResult Sema::ActOnNumericConstant(const Token &Tok) {
Diag(Tok.getLocation(), diag::ext_longlong); Diag(Tok.getLocation(), diag::ext_longlong);
// Get the value in the widest-possible width. // Get the value in the widest-possible width.
llvm::APInt ResultVal(Context.Target.getIntMaxTWidth( llvm::APInt ResultVal(Context.Target.getIntMaxTWidth(), 0);
Context.getFullLoc(Tok.getLocation())), 0);
if (Literal.GetIntegerValue(ResultVal)) { if (Literal.GetIntegerValue(ResultVal)) {
// If this value didn't fit into uintmax_t, warn and force to ull. // If this value didn't fit into uintmax_t, warn and force to ull.
Diag(Tok.getLocation(), diag::warn_integer_too_large); Diag(Tok.getLocation(), diag::warn_integer_too_large);
t = Context.UnsignedLongLongTy; t = Context.UnsignedLongLongTy;
assert(Context.getTypeSize(t, Tok.getLocation()) == assert(Context.getTypeSize(t) == ResultVal.getBitWidth() &&
ResultVal.getBitWidth() && "long long is not intmax_t?"); "long long is not intmax_t?");
} else { } else {
// If this value fits into a ULL, try to figure out what else it fits into // If this value fits into a ULL, try to figure out what else it fits into
// according to the rules of C99 6.4.4.1p5. // according to the rules of C99 6.4.4.1p5.
@ -245,8 +239,8 @@ Action::ExprResult Sema::ActOnNumericConstant(const Token &Tok) {
// Check from smallest to largest, picking the smallest type we can. // Check from smallest to largest, picking the smallest type we can.
if (!Literal.isLong && !Literal.isLongLong) { if (!Literal.isLong && !Literal.isLongLong) {
// Are int/unsigned possibilities? // Are int/unsigned possibilities?
unsigned IntSize = static_cast<unsigned>( unsigned IntSize =
Context.getTypeSize(Context.IntTy,Tok.getLocation())); static_cast<unsigned>(Context.getTypeSize(Context.IntTy));
// Does it fit in a unsigned int? // Does it fit in a unsigned int?
if (ResultVal.isIntN(IntSize)) { if (ResultVal.isIntN(IntSize)) {
// Does it fit in a signed int? // Does it fit in a signed int?
@ -262,8 +256,8 @@ Action::ExprResult Sema::ActOnNumericConstant(const Token &Tok) {
// Are long/unsigned long possibilities? // Are long/unsigned long possibilities?
if (t.isNull() && !Literal.isLongLong) { if (t.isNull() && !Literal.isLongLong) {
unsigned LongSize = static_cast<unsigned>( unsigned LongSize =
Context.getTypeSize(Context.LongTy, Tok.getLocation())); static_cast<unsigned>(Context.getTypeSize(Context.LongTy));
// Does it fit in a unsigned long? // Does it fit in a unsigned long?
if (ResultVal.isIntN(LongSize)) { if (ResultVal.isIntN(LongSize)) {
@ -279,8 +273,8 @@ Action::ExprResult Sema::ActOnNumericConstant(const Token &Tok) {
// Finally, check long long if needed. // Finally, check long long if needed.
if (t.isNull()) { if (t.isNull()) {
unsigned LongLongSize = static_cast<unsigned>( unsigned LongLongSize =
Context.getTypeSize(Context.LongLongTy, Tok.getLocation())); static_cast<unsigned>(Context.getTypeSize(Context.LongLongTy));
// Does it fit in a unsigned long long? // Does it fit in a unsigned long long?
if (ResultVal.isIntN(LongLongSize)) { if (ResultVal.isIntN(LongLongSize)) {
@ -718,8 +712,7 @@ bool Sema::CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty) {
assert(VectorTy->isVectorType() && "Not a vector type!"); assert(VectorTy->isVectorType() && "Not a vector type!");
if (Ty->isVectorType() || Ty->isIntegerType()) { if (Ty->isVectorType() || Ty->isIntegerType()) {
if (Context.getTypeSize(VectorTy, SourceLocation()) != if (Context.getTypeSize(VectorTy) != Context.getTypeSize(Ty))
Context.getTypeSize(Ty, SourceLocation()))
return Diag(R.getBegin(), return Diag(R.getBegin(),
Ty->isVectorType() ? Ty->isVectorType() ?
diag::err_invalid_conversion_between_vectors : diag::err_invalid_conversion_between_vectors :
@ -1210,8 +1203,7 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) {
lhsType->isVectorType() && rhsType->isVectorType()) { lhsType->isVectorType() && rhsType->isVectorType()) {
if ((lhsType->isIntegerType() && rhsType->isIntegerType()) || if ((lhsType->isIntegerType() && rhsType->isIntegerType()) ||
(lhsType->isRealFloatingType() && rhsType->isRealFloatingType())) { (lhsType->isRealFloatingType() && rhsType->isRealFloatingType())) {
if (Context.getTypeSize(lhsType, SourceLocation()) == if (Context.getTypeSize(lhsType) == Context.getTypeSize(rhsType))
Context.getTypeSize(rhsType, SourceLocation()))
return Compatible; return Compatible;
} }
} }

View File

@ -307,8 +307,7 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch,
// Get the bitwidth of the switched-on value before promotions. We must // Get the bitwidth of the switched-on value before promotions. We must
// convert the integer case values to this width before comparison. // convert the integer case values to this width before comparison.
unsigned CondWidth = unsigned CondWidth = static_cast<unsigned>(Context.getTypeSize(CondType));
static_cast<unsigned>(Context.getTypeSize(CondType, SwitchLoc));
bool CondIsSigned = CondType->isSignedIntegerType(); bool CondIsSigned = CondType->isSignedIntegerType();
// Accumulate all of the case values in a vector so that we can sort them // Accumulate all of the case values in a vector so that we can sort them

View File

@ -261,24 +261,24 @@ public:
/// getTypeInfo - Get the size and alignment of the specified complete type in /// getTypeInfo - Get the size and alignment of the specified complete type in
/// bits. /// bits.
std::pair<uint64_t, unsigned> getTypeInfo(QualType T, SourceLocation L); std::pair<uint64_t, unsigned> getTypeInfo(QualType T);
/// getTypeSize - Return the size of the specified type, in bits. This method /// getTypeSize - Return the size of the specified type, in bits. This method
/// does not work on incomplete types. /// does not work on incomplete types.
uint64_t getTypeSize(QualType T, SourceLocation L) { uint64_t getTypeSize(QualType T) {
return getTypeInfo(T, L).first; return getTypeInfo(T).first;
} }
/// getTypeAlign - Return the alignment of the specified type, in bits. This /// getTypeAlign - Return the alignment of the specified type, in bits. This
/// method does not work on incomplete types. /// method does not work on incomplete types.
unsigned getTypeAlign(QualType T, SourceLocation L) { unsigned getTypeAlign(QualType T) {
return getTypeInfo(T, L).second; return getTypeInfo(T).second;
} }
/// getASTRecordLayout - Get or compute information about the layout of the /// getASTRecordLayout - Get or compute information about the layout of the
/// specified record (struct/union/class), which indicates its size and field /// specified record (struct/union/class), which indicates its size and field
/// position information. /// position information.
const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D, SourceLocation L); const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D);
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//
// Type Operators // Type Operators

View File

@ -286,7 +286,7 @@ protected:
} }
inline NonLVal MakeConstantVal(uint64_t X, Expr* Ex) { inline NonLVal MakeConstantVal(uint64_t X, Expr* Ex) {
return NonLVal::MakeVal(ValMgr, X, Ex->getType(), Ex->getLocStart()); return NonLVal::MakeVal(ValMgr, X, Ex->getType());
} }
/// Assume - Create new state by assuming that a given expression /// Assume - Create new state by assuming that a given expression

View File

@ -123,8 +123,7 @@ public:
void print(std::ostream& Out) const; void print(std::ostream& Out) const;
// Utility methods to create NonLVals. // Utility methods to create NonLVals.
static NonLVal MakeVal(ValueManager& ValMgr, uint64_t X, QualType T, static NonLVal MakeVal(ValueManager& ValMgr, uint64_t X, QualType T);
SourceLocation Loc = SourceLocation());
static NonLVal MakeVal(ValueManager& ValMgr, IntegerLiteral* I); static NonLVal MakeVal(ValueManager& ValMgr, IntegerLiteral* I);

View File

@ -49,17 +49,14 @@ public:
const llvm::APSInt& getValue(const llvm::APSInt& X); const llvm::APSInt& getValue(const llvm::APSInt& X);
const llvm::APSInt& getValue(uint64_t X, unsigned BitWidth, bool isUnsigned); const llvm::APSInt& getValue(uint64_t X, unsigned BitWidth, bool isUnsigned);
const llvm::APSInt& getValue(uint64_t X, QualType T, const llvm::APSInt& getValue(uint64_t X, QualType T);
SourceLocation Loc = SourceLocation());
inline const llvm::APSInt& getZeroWithPtrWidth() { inline const llvm::APSInt& getZeroWithPtrWidth() {
return getValue(0, Ctx.getTypeSize(Ctx.VoidPtrTy, SourceLocation()), true); return getValue(0, Ctx.getTypeSize(Ctx.VoidPtrTy), true);
} }
inline const llvm::APSInt& getTruthValue(bool b) { inline const llvm::APSInt& getTruthValue(bool b) {
return getValue(b ? 1 : 0, return getValue(b ? 1 : 0, Ctx.getTypeSize(Ctx.IntTy), false);
Ctx.getTypeSize(Ctx.IntTy, SourceLocation()),
false);
} }
const SymIntConstraint& getConstraint(SymbolID sym, BinaryOperator::Opcode Op, const SymIntConstraint& getConstraint(SymbolID sym, BinaryOperator::Opcode Op,

View File

@ -14,7 +14,6 @@
#ifndef LLVM_CLANG_BASIC_TARGETINFO_H #ifndef LLVM_CLANG_BASIC_TARGETINFO_H
#define LLVM_CLANG_BASIC_TARGETINFO_H #define LLVM_CLANG_BASIC_TARGETINFO_H
#include "clang/Basic/SourceLocation.h"
#include "llvm/Support/DataTypes.h" #include "llvm/Support/DataTypes.h"
#include <vector> #include <vector>
#include <string> #include <string>
@ -66,79 +65,77 @@ public:
/// isCharSigned - Return true if 'char' is 'signed char' or false if it is /// isCharSigned - Return true if 'char' is 'signed char' or false if it is
/// treated as 'unsigned char'. This is implementation defined according to /// treated as 'unsigned char'. This is implementation defined according to
/// C99 6.2.5p15. In our implementation, this is target-specific. /// C99 6.2.5p15. In our implementation, this is target-specific.
bool isCharSigned(FullSourceLoc Loc) { bool isCharSigned() {
// FIXME: implement correctly. // FIXME: implement correctly.
return true; return true;
} }
/// getPointerWidth - Return the width of pointers on this target, we /// getPointerWidth - Return the width of pointers on this target, we
/// currently assume one pointer type. /// currently assume one pointer type.
void getPointerInfo(uint64_t &Size, unsigned &Align, FullSourceLoc Loc) { void getPointerInfo(uint64_t &Size, unsigned &Align) {
Size = 32; // FIXME: implement correctly. Size = 32; // FIXME: implement correctly.
Align = 32; Align = 32;
} }
/// getBoolInfo - Return the size of '_Bool' and C++ 'bool' for this target, /// getBoolInfo - Return the size of '_Bool' and C++ 'bool' for this target,
/// in bits. /// in bits.
void getBoolInfo(uint64_t &Size, unsigned &Align, FullSourceLoc Loc) { void getBoolInfo(uint64_t &Size, unsigned &Align) {
Size = Align = 8; // FIXME: implement correctly: wrong for ppc32. Size = Align = 8; // FIXME: implement correctly: wrong for ppc32.
} }
/// getCharInfo - Return the size of 'char', 'signed char' and /// getCharInfo - Return the size of 'char', 'signed char' and
/// 'unsigned char' for this target, in bits. /// 'unsigned char' for this target, in bits.
void getCharInfo(uint64_t &Size, unsigned &Align, FullSourceLoc Loc) { void getCharInfo(uint64_t &Size, unsigned &Align) {
Size = Align = 8; // FIXME: implement correctly. Size = Align = 8; // FIXME: implement correctly.
} }
/// getShortInfo - Return the size of 'signed short' and 'unsigned short' for /// getShortInfo - Return the size of 'signed short' and 'unsigned short' for
/// this target, in bits. /// this target, in bits.
void getShortInfo(uint64_t &Size, unsigned &Align, FullSourceLoc Loc) { void getShortInfo(uint64_t &Size, unsigned &Align) {
Size = Align = 16; // FIXME: implement correctly. Size = Align = 16; // FIXME: implement correctly.
} }
/// getIntInfo - Return the size of 'signed int' and 'unsigned int' for this /// getIntInfo - Return the size of 'signed int' and 'unsigned int' for this
/// target, in bits. /// target, in bits.
void getIntInfo(uint64_t &Size, unsigned &Align, FullSourceLoc Loc) { void getIntInfo(uint64_t &Size, unsigned &Align) {
Size = Align = 32; // FIXME: implement correctly. Size = Align = 32; // FIXME: implement correctly.
} }
/// getLongInfo - Return the size of 'signed long' and 'unsigned long' for /// getLongInfo - Return the size of 'signed long' and 'unsigned long' for
/// this target, in bits. /// this target, in bits.
void getLongInfo(uint64_t &Size, unsigned &Align, FullSourceLoc Loc) { void getLongInfo(uint64_t &Size, unsigned &Align) {
Size = Align = 32; // FIXME: implement correctly: wrong for ppc64/x86-64 Size = Align = 32; // FIXME: implement correctly: wrong for ppc64/x86-64
} }
/// getLongLongInfo - Return the size of 'signed long long' and /// getLongLongInfo - Return the size of 'signed long long' and
/// 'unsigned long long' for this target, in bits. /// 'unsigned long long' for this target, in bits.
void getLongLongInfo(uint64_t &Size, unsigned &Align, void getLongLongInfo(uint64_t &Size, unsigned &Align) {
FullSourceLoc Loc) {
Size = Align = 64; // FIXME: implement correctly. Size = Align = 64; // FIXME: implement correctly.
} }
/// getFloatInfo - Characterize 'float' for this target. /// getFloatInfo - Characterize 'float' for this target.
void getFloatInfo(uint64_t &Size, unsigned &Align, void getFloatInfo(uint64_t &Size, unsigned &Align,
const llvm::fltSemantics *&Format, FullSourceLoc Loc); const llvm::fltSemantics *&Format);
/// getDoubleInfo - Characterize 'double' for this target. /// getDoubleInfo - Characterize 'double' for this target.
void getDoubleInfo(uint64_t &Size, unsigned &Align, void getDoubleInfo(uint64_t &Size, unsigned &Align,
const llvm::fltSemantics *&Format, FullSourceLoc Loc); const llvm::fltSemantics *&Format);
/// getLongDoubleInfo - Characterize 'long double' for this target. /// getLongDoubleInfo - Characterize 'long double' for this target.
void getLongDoubleInfo(uint64_t &Size, unsigned &Align, void getLongDoubleInfo(uint64_t &Size, unsigned &Align,
const llvm::fltSemantics *&Format, FullSourceLoc Loc); const llvm::fltSemantics *&Format);
/// getWCharInfo - Return the size of wchar_t in bits. /// getWCharInfo - Return the size of wchar_t in bits.
/// ///
void getWCharInfo(uint64_t &Size, unsigned &Align, void getWCharInfo(uint64_t &Size, unsigned &Align) {
FullSourceLoc Loc) { if (!WCharWidth) ComputeWCharInfo();
if (!WCharWidth) ComputeWCharInfo(Loc);
Size = WCharWidth; Size = WCharWidth;
Align = WCharAlign; Align = WCharAlign;
} }
/// getIntMaxTWidth - Return the size of intmax_t and uintmax_t for this /// getIntMaxTWidth - Return the size of intmax_t and uintmax_t for this
/// target, in bits. /// target, in bits.
unsigned getIntMaxTWidth(FullSourceLoc Loc) { unsigned getIntMaxTWidth() {
// FIXME: implement correctly. // FIXME: implement correctly.
return 64; return 64;
} }
@ -183,39 +180,42 @@ public:
///===---- Some helper methods ------------------------------------------===// ///===---- Some helper methods ------------------------------------------===//
unsigned getBoolWidth(FullSourceLoc Loc) { unsigned getBoolWidth() {
uint64_t Size; unsigned Align; uint64_t Size; unsigned Align;
getBoolInfo(Size, Align, Loc); getBoolInfo(Size, Align);
return static_cast<unsigned>(Size); return static_cast<unsigned>(Size);
} }
unsigned getCharWidth(FullSourceLoc Loc) { unsigned getCharWidth(bool isWide = false) {
uint64_t Size; unsigned Align; uint64_t Size; unsigned Align;
getCharInfo(Size, Align, Loc); if (isWide)
getWCharInfo(Size, Align);
else
getCharInfo(Size, Align);
return static_cast<unsigned>(Size); return static_cast<unsigned>(Size);
} }
unsigned getWCharWidth(FullSourceLoc Loc) { unsigned getWCharWidth() {
uint64_t Size; unsigned Align; uint64_t Size; unsigned Align;
getWCharInfo(Size, Align, Loc); getWCharInfo(Size, Align);
return static_cast<unsigned>(Size); return static_cast<unsigned>(Size);
} }
unsigned getIntWidth(FullSourceLoc Loc) { unsigned getIntWidth() {
uint64_t Size; unsigned Align; uint64_t Size; unsigned Align;
getIntInfo(Size, Align, Loc); getIntInfo(Size, Align);
return static_cast<unsigned>(Size); return static_cast<unsigned>(Size);
} }
unsigned getLongWidth(FullSourceLoc Loc) { unsigned getLongWidth() {
uint64_t Size; unsigned Align; uint64_t Size; unsigned Align;
getLongInfo(Size, Align, Loc); getLongInfo(Size, Align);
return static_cast<unsigned>(Size); return static_cast<unsigned>(Size);
} }
unsigned getLongLongWidth(FullSourceLoc Loc) { unsigned getLongLongWidth() {
uint64_t Size; unsigned Align; uint64_t Size; unsigned Align;
getLongLongInfo(Size, Align, Loc); getLongLongInfo(Size, Align);
return static_cast<unsigned>(Size); return static_cast<unsigned>(Size);
} }
@ -233,7 +233,7 @@ public:
32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"; 32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128";
} }
private: private:
void ComputeWCharInfo(FullSourceLoc Loc); void ComputeWCharInfo();
}; };