diff --git a/clang/AST/ASTContext.cpp b/clang/AST/ASTContext.cpp index 5dd7d9aeebe0..3d312fa4a808 100644 --- a/clang/AST/ASTContext.cpp +++ b/clang/AST/ASTContext.cpp @@ -182,7 +182,7 @@ void ASTContext::InitBuiltinTypes() { std::pair ASTContext::getTypeInfo(QualType T) { T = T.getCanonicalType(); - uint64_t Size; + uint64_t Width; unsigned Align; switch (T->getTypeClass()) { case Type::TypeName: assert(0 && "Not a canonical type!"); @@ -196,7 +196,7 @@ ASTContext::getTypeInfo(QualType T) { ConstantArrayType *CAT = cast(T); std::pair EltInfo = getTypeInfo(CAT->getElementType()); - Size = EltInfo.first*CAT->getSize().getZExtValue(); + Width = EltInfo.first*CAT->getSize().getZExtValue(); Align = EltInfo.second; break; } @@ -204,68 +204,75 @@ ASTContext::getTypeInfo(QualType T) { case Type::Vector: { std::pair EltInfo = getTypeInfo(cast(T)->getElementType()); - Size = EltInfo.first*cast(T)->getNumElements(); + Width = EltInfo.first*cast(T)->getNumElements(); // FIXME: Vector alignment is not the alignment of its elements. Align = EltInfo.second; break; } - case Type::Builtin: { + case Type::Builtin: // FIXME: need to use TargetInfo to derive the target specific sizes. This // implementation will suffice for play with vector support. - const llvm::fltSemantics *F; switch (cast(T)->getKind()) { default: assert(0 && "Unknown builtin type!"); case BuiltinType::Void: assert(0 && "Incomplete types have no size!"); case BuiltinType::Bool: - Target.getBoolInfo(Size, Align); + Width = Target.getBoolWidth(); + Align = Target.getBoolAlign(); break; case BuiltinType::Char_S: case BuiltinType::Char_U: case BuiltinType::UChar: case BuiltinType::SChar: - Target.getCharInfo(Size, Align); + Width = Target.getCharWidth(); + Align = Target.getCharAlign(); break; case BuiltinType::UShort: case BuiltinType::Short: - Target.getShortInfo(Size, Align); + Width = Target.getShortWidth(); + Align = Target.getShortAlign(); break; case BuiltinType::UInt: case BuiltinType::Int: - Target.getIntInfo(Size, Align); + Width = Target.getIntWidth(); + Align = Target.getIntAlign(); break; case BuiltinType::ULong: case BuiltinType::Long: - Target.getLongInfo(Size, Align); + Width = Target.getLongWidth(); + Align = Target.getLongAlign(); break; case BuiltinType::ULongLong: case BuiltinType::LongLong: - Target.getLongLongInfo(Size, Align); + Width = Target.getLongLongWidth(); + Align = Target.getLongLongAlign(); break; case BuiltinType::Float: - Target.getFloatInfo(Size, Align, F); + Width = Target.getFloatWidth(); + Align = Target.getFloatAlign(); break; case BuiltinType::Double: - Target.getDoubleInfo(Size, Align, F); + Width = Target.getDoubleWidth(); + Align = Target.getDoubleAlign(); break; case BuiltinType::LongDouble: - Target.getLongDoubleInfo(Size, Align, F); + Width = Target.getLongDoubleWidth(); + Align = Target.getLongDoubleAlign(); break; } break; - } case Type::ASQual: // FIXME: Pointers into different addr spaces could have different sizes and // alignment requirements: getPointerInfo should take an AddrSpace. return getTypeInfo(QualType(cast(T)->getBaseType(), 0)); case Type::ObjCQualifiedId: - Size = Target.getPointerWidth(0); + Width = Target.getPointerWidth(0); Align = Target.getPointerAlign(0); break; case Type::Pointer: { unsigned AS = cast(T)->getPointeeType().getAddressSpace(); - Size = Target.getPointerWidth(AS); + Width = Target.getPointerWidth(AS); Align = Target.getPointerAlign(AS); break; } @@ -281,7 +288,7 @@ ASTContext::getTypeInfo(QualType T) { // size. std::pair EltInfo = getTypeInfo(cast(T)->getElementType()); - Size = EltInfo.first*2; + Width = EltInfo.first*2; Align = EltInfo.second; break; } @@ -289,7 +296,7 @@ ASTContext::getTypeInfo(QualType T) { TagType *TT = cast(T); if (RecordType *RT = dyn_cast(TT)) { const ASTRecordLayout &Layout = getASTRecordLayout(RT->getDecl()); - Size = Layout.getSize(); + Width = Layout.getSize(); Align = Layout.getAlignment(); } else if (EnumDecl *ED = dyn_cast(TT->getDecl())) { return getTypeInfo(ED->getIntegerType()); @@ -300,7 +307,7 @@ ASTContext::getTypeInfo(QualType T) { } assert(Align && (Align & (Align-1)) == 0 && "Alignment must be power of 2"); - return std::make_pair(Size, Align); + return std::make_pair(Width, Align); } /// getASTRecordLayout - Get or compute information about the layout of the diff --git a/clang/Basic/TargetInfo.cpp b/clang/Basic/TargetInfo.cpp index 8def507c0a70..5364affe589c 100644 --- a/clang/Basic/TargetInfo.cpp +++ b/clang/Basic/TargetInfo.cpp @@ -24,24 +24,16 @@ TargetInfo::~TargetInfo() {} //===----------------------------------------------------------------------===// // FIXME: These are temporary hacks. -void TargetInfo::getFloatInfo(uint64_t &Size, unsigned &Align, - const llvm::fltSemantics *&Format) const { - Align = 32; // FIXME: implement correctly. - Size = 32; - Format = &llvm::APFloat::IEEEsingle; +const llvm::fltSemantics *TargetInfo::getFloatFormat() const { + return &llvm::APFloat::IEEEsingle; } -void TargetInfo::getDoubleInfo(uint64_t &Size, unsigned &Align, - const llvm::fltSemantics *&Format) const { - Size = 64; // FIXME: implement correctly. - Align = 32; - Format = &llvm::APFloat::IEEEdouble; +const llvm::fltSemantics *TargetInfo::getDoubleFormat() const { + return &llvm::APFloat::IEEEdouble; } -void TargetInfo::getLongDoubleInfo(uint64_t &Size, unsigned &Align, - const llvm::fltSemantics *&Format) const { - Size = Align = 64; // FIXME: implement correctly. - Format = &llvm::APFloat::IEEEdouble; +const llvm::fltSemantics *TargetInfo::getLongDoubleFormat() const { //Size = 80; Align = 32; // FIXME: implement correctly. //Format = &llvm::APFloat::x87DoubleExtended; + return &llvm::APFloat::IEEEdouble; } diff --git a/clang/Sema/SemaExpr.cpp b/clang/Sema/SemaExpr.cpp index f1b6ea222ce2..d756345c1a86 100644 --- a/clang/Sema/SemaExpr.cpp +++ b/clang/Sema/SemaExpr.cpp @@ -190,17 +190,16 @@ Action::ExprResult Sema::ActOnNumericConstant(const Token &Tok) { if (Literal.isFloatingLiteral()) { QualType Ty; const llvm::fltSemantics *Format; - uint64_t Size; unsigned Align; if (Literal.isFloat) { Ty = Context.FloatTy; - Context.Target.getFloatInfo(Size, Align, Format); - } else if (Literal.isLong) { - Ty = Context.LongDoubleTy; - Context.Target.getLongDoubleInfo(Size, Align, Format); - } else { + Format = Context.Target.getFloatFormat(); + } else if (!Literal.isLong) { Ty = Context.DoubleTy; - Context.Target.getDoubleInfo(Size, Align, Format); + Format = Context.Target.getDoubleFormat(); + } else { + Ty = Context.LongDoubleTy; + Format = Context.Target.getLongDoubleFormat(); } // isExact will be set by GetFloatValue(). diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index 4fb50bca9192..2d2aca5698b6 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -33,13 +33,13 @@ class TargetInfo { std::string Triple; protected: /// These are all caches for target values. + bool CharIsSigned; unsigned WCharWidth, WCharAlign; - //==----------------------------------------------------------------==/ - // TargetInfo Construction. - //==----------------------------------------------------------------==/ + // TargetInfo Constructor. TargetInfo(const std::string &T) : Triple(T) { - // Set defaults. + // Set defaults. These should be overridden by concrete targets as needed. + CharIsSigned = true; WCharWidth = WCharAlign = 32; } @@ -59,67 +59,67 @@ public: /// isCharSigned - Return true if 'char' is 'signed char' or false if it is /// treated as 'unsigned char'. This is implementation defined according to /// C99 6.2.5p15. In our implementation, this is target-specific. - bool isCharSigned() const { - // FIXME: implement correctly. - return true; - } + bool isCharSigned() const { return CharIsSigned; } /// getPointerWidth - Return the width of pointers on this target, for the /// specified address space. FIXME: implement correctly. uint64_t getPointerWidth(unsigned AddrSpace) const { return 32; } uint64_t getPointerAlign(unsigned AddrSpace) const { return 32; } - /// getBoolInfo - Return the size of '_Bool' and C++ 'bool' for this target, - /// in bits. - void getBoolInfo(uint64_t &Size, unsigned &Align) const { - Size = Align = 8; // FIXME: implement correctly: wrong for ppc32. + /// getBoolWidth/Align - Return the size of '_Bool' and C++ 'bool' for this + /// target, in bits. + unsigned getBoolWidth(bool isWide = false) const { return 8; } // FIXME + unsigned getBoolAlign(bool isWide = false) const { return 8; } // FIXME + + unsigned getCharWidth(bool isWide = false) const { + return isWide ? getWCharWidth() : 8; // FIXME + } + unsigned getCharAlign(bool isWide = false) const { + return isWide ? getWCharAlign() : 8; // FIXME } - /// getCharInfo - Return the size of 'char', 'signed char' and - /// 'unsigned char' for this target, in bits. - void getCharInfo(uint64_t &Size, unsigned &Align) const { - Size = Align = 8; // FIXME: implement correctly. - } + /// getShortWidth/Align - Return the size of 'signed short' and + /// 'unsigned short' for this target, in bits. + unsigned getShortWidth() const { return 16; } // FIXME + unsigned getShortAlign() const { return 16; } // FIXME - /// getShortInfo - Return the size of 'signed short' and 'unsigned short' for - /// this target, in bits. - void getShortInfo(uint64_t &Size, unsigned &Align) const { - Size = Align = 16; // FIXME: implement correctly. - } + /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for + /// this target, in bits. + unsigned getIntWidth() const { return 32; } // FIXME + unsigned getIntAlign() const { return 32; } // FIXME - /// getIntInfo - Return the size of 'signed int' and 'unsigned int' for this - /// target, in bits. - void getIntInfo(uint64_t &Size, unsigned &Align) const { - Size = Align = 32; // FIXME: implement correctly. - } + /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long' + /// for this target, in bits. + unsigned getLongWidth() const { return 32; } // FIXME + unsigned getLongAlign() const { return 32; } // FIXME - /// getLongInfo - Return the size of 'signed long' and 'unsigned long' for - /// this target, in bits. - void getLongInfo(uint64_t &Size, unsigned &Align) const { - Size = Align = 32; // FIXME: implement correctly: wrong for ppc64/x86-64 - } - - /// getLongLongInfo - Return the size of 'signed long long' and - /// 'unsigned long long' for this target, in bits. - void getLongLongInfo(uint64_t &Size, unsigned &Align) const { - Size = Align = 64; // FIXME: implement correctly. - } - - /// getFloatInfo - Characterize 'float' for this target. - void getFloatInfo(uint64_t &Size, unsigned &Align, - const llvm::fltSemantics *&Format) const; - - /// getDoubleInfo - Characterize 'double' for this target. - void getDoubleInfo(uint64_t &Size, unsigned &Align, - const llvm::fltSemantics *&Format) const; - - /// getLongDoubleInfo - Characterize 'long double' for this target. - void getLongDoubleInfo(uint64_t &Size, unsigned &Align, - const llvm::fltSemantics *&Format) const; + /// getLongLongWidth/Align - Return the size of 'signed long long' and + /// 'unsigned long long' for this target, in bits. + unsigned getLongLongWidth() const { return 64; } // FIXME + unsigned getLongLongAlign() const { return 64; } // FIXME + /// getWcharWidth/Align - Return the size of 'wchar_t' for this target, in + /// bits. unsigned getWCharWidth() const { return WCharWidth; } unsigned getWCharAlign() const { return WCharAlign; } + /// getFloatWidth/Align/Format - Return the size/align/format of 'float'. + unsigned getFloatWidth() const { return 32; } // FIXME + unsigned getFloatAlign() const { return 32; } // FIXME + const llvm::fltSemantics *getFloatFormat() const; + + /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'. + unsigned getDoubleWidth() const { return 64; } // FIXME + unsigned getDoubleAlign() const { return 32; } // FIXME + const llvm::fltSemantics *getDoubleFormat() const; + + /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long + /// double'. + unsigned getLongDoubleWidth() const { return 64; } // FIXME + unsigned getLongDoubleAlign() const { return 64; } // FIXME + const llvm::fltSemantics *getLongDoubleFormat() const; + + /// getIntMaxTWidth - Return the size of intmax_t and uintmax_t for this /// target, in bits. unsigned getIntMaxTWidth() const { @@ -167,47 +167,13 @@ public: // Returns a string of target-specific clobbers, in LLVM format. virtual const char *getClobbers() const = 0; - ///===---- Some helper methods ------------------------------------------===// - - unsigned getBoolWidth() const { - uint64_t Size; unsigned Align; - getBoolInfo(Size, Align); - return static_cast(Size); - } - - unsigned getCharWidth(bool isWide = false) const { - if (isWide) - return WCharWidth; - uint64_t Size; unsigned Align; - getCharInfo(Size, Align); - return static_cast(Size); - } - - - unsigned getIntWidth() const { - uint64_t Size; unsigned Align; - getIntInfo(Size, Align); - return static_cast(Size); - } - - unsigned getLongWidth() const { - uint64_t Size; unsigned Align; - getLongInfo(Size, Align); - return static_cast(Size); - } - - unsigned getLongLongWidth() const { - uint64_t Size; unsigned Align; - getLongLongInfo(Size, Align); - return static_cast(Size); - } /// getTargetPrefix - Return the target prefix used for identifying /// llvm intrinsics. virtual const char *getTargetPrefix() const = 0; /// getTargetTriple - Return the target triple of the primary target. - virtual const char *getTargetTriple() const { + const char *getTargetTriple() const { return Triple.c_str(); }