Made the mechanism of defining preprocessor defs for maxint, ptrdiff_t, wchar

etc more generic. For some targets, long may not be equal to pointer size. For
example: PIC16 has int as i16, ptr as i16 but long as i32.

Also fixed a few build warnings in assert() functions in CFRefCount.cpp,
CGDecl.cpp, SemaDeclCXX.cpp and ParseDeclCXX.cpp.

llvm-svn: 58501
This commit is contained in:
Sanjiv Gupta 2008-10-31 09:52:39 +00:00
parent ada702ef45
commit d79592448b
8 changed files with 106 additions and 48 deletions

View File

@ -58,6 +58,24 @@ public:
virtual ~TargetInfo();
///===---- Target Data Type Query Methods -------------------------------===//
enum IntType {
NoInt = 0x0,
SignedShort,
UnsignedShort,
SignedInt,
UnsignedInt,
SignedLong,
UnsignedLong,
SignedLongLong,
UnsignedLongLong
} SizeType, IntMaxType, UIntMaxType, PtrDiffType, WCharType;
enum IntType getSizeType() const {return SizeType;}
enum IntType getIntMaxType() const {return IntMaxType;}
enum IntType getUIntMaxType() const {return UIntMaxType;}
enum IntType getPtrDiffType(unsigned AddrSpace) const {
return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace);
}
enum IntType getWCharType() const {return WCharType;}
/// isCharSigned - Return true if 'char' is 'signed char' or false if it is
/// treated as 'unsigned char'. This is implementation defined according to
@ -219,7 +237,9 @@ protected:
virtual uint64_t getPointerAlignV(unsigned AddrSpace) const {
return PointerAlign;
}
virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const {
return PtrDiffType;
}
virtual void getGCCRegNames(const char * const *&Names,
unsigned &NumNames) const = 0;
virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,

View File

@ -1875,7 +1875,7 @@ CFRefCount::HandleSymbolDeath(GRStateManager& VMgr,
RefVal V, bool& hasLeak) {
GRStateRef state(St, VMgr);
assert (!V.isReturnedOwned() || CD &&
assert ((!V.isReturnedOwned() || CD) &&
"CodeDecl must be available for reporting ReturnOwned errors.");
if (V.isReturnedOwned() && V.getCount() == 0)

View File

@ -34,6 +34,11 @@ TargetInfo::TargetInfo(const std::string &T) : Triple(T) {
DoubleAlign = 64;
LongDoubleWidth = 64;
LongDoubleAlign = 64;
SizeType = UnsignedInt;
IntMaxType = SignedLongLong;
UIntMaxType = UnsignedLongLong;
PtrDiffType = SignedLongLong;
WCharType = UnsignedInt;
FloatFormat = &llvm::APFloat::IEEEsingle;
DoubleFormat = &llvm::APFloat::IEEEdouble;
LongDoubleFormat = &llvm::APFloat::IEEEdouble;

View File

@ -801,11 +801,17 @@ namespace {
class PIC16TargetInfo : public TargetInfo{
public:
PIC16TargetInfo(const std::string& triple) : TargetInfo(triple) {
// FIXME: Is IntAlign really supposed to be 16? There seems
// little point on a platform with 8-bit loads.
IntWidth = IntAlign = LongAlign = LongLongAlign = PointerWidth = 16;
LongWidth = 16;
IntWidth = 16;
LongWidth = LongLongWidth = 32;
PointerWidth = 16;
IntAlign = 8;
LongAlign = LongLongAlign = 8;
PointerAlign = 8;
SizeType = UnsignedInt;
IntMaxType = SignedLong;
UIntMaxType = UnsignedLong;
PtrDiffType = SignedShort;
WCharType = UnsignedInt;
DescriptionString = "e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8";
}
virtual uint64_t getPointerWidthV(unsigned AddrSpace) const { return 16; }

View File

@ -198,7 +198,7 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
/// for the specified parameter and set up LocalDeclMap.
void CodeGenFunction::EmitParmDecl(const VarDecl &D, llvm::Value *Arg) {
// FIXME: Why isn't ImplicitParamDecl a ParmVarDecl?
assert(isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D) &&
assert((isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D)) &&
"Invalid argument to EmitParmDecl");
QualType Ty = D.getType();

View File

@ -553,9 +553,11 @@ static void InitializePredefinedMacros(Preprocessor &PP,
DefineBuiltinMacro(Buf, "__INT_MAX__=32767");
else
assert(0 && "Unknown integer size");
assert(TI.getLongLongWidth() == 64 && "Only support 64-bit long long so far");
DefineBuiltinMacro(Buf, "__LONG_LONG_MAX__=9223372036854775807LL");
if (TI.getLongLongWidth() == 64)
DefineBuiltinMacro(Buf, "__LONG_LONG_MAX__=9223372036854775807LL");
else if (TI.getLongLongWidth() == 32)
DefineBuiltinMacro(Buf, "__LONG_LONG_MAX__=2147483647L");
if (TI.getLongWidth() == 32)
DefineBuiltinMacro(Buf, "__LONG_MAX__=2147483647L");
@ -565,41 +567,67 @@ static void InitializePredefinedMacros(Preprocessor &PP,
DefineBuiltinMacro(Buf, "__LONG_MAX__=32767L");
else
assert(0 && "Unknown long size");
char MacroBuf[60];
sprintf(MacroBuf, "__INTMAX_MAX__=%lld",
(TI.getIntMaxType() == TargetInfo::UnsignedLongLong?
(1LL<<(TI.getLongLongWidth() -1)) :
(1LL<<(TI.getLongLongWidth() -2) -1)));
DefineBuiltinMacro(Buf, MacroBuf);
// For "32-bit" targets, GCC generally defines intmax to be 'long long' and
// ptrdiff_t to be 'int'. On "64-bit" targets, it defines intmax to be long,
// and ptrdiff_t to be 'long int'. This sort of stuff shouldn't matter in
// theory, but can affect C++ overloading, stringizing, etc.
if (TI.getPointerWidth(0) == TI.getLongLongWidth()) {
// If sizeof(void*) == sizeof(long long) assume we have an LP64 target,
// because we assume sizeof(long) always is sizeof(void*) currently.
assert(TI.getPointerWidth(0) == TI.getLongWidth() &&
TI.getLongWidth() == 64 &&
TI.getIntWidth() == 32 && "Not I32 LP64?");
assert(TI.getIntMaxTWidth() == 64);
DefineBuiltinMacro(Buf, "__INTMAX_MAX__=9223372036854775807L");
DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=long int");
DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=long int");
DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=long unsigned int");
} else {
// Otherwise we know that the pointer is smaller than long long. We continue
// to assume that sizeof(void*) == sizeof(long).
assert(TI.getPointerWidth(0) < TI.getLongLongWidth() &&
TI.getPointerWidth(0) == TI.getLongWidth() &&
"Unexpected target sizes");
// We currently only support targets where long is 32-bit. This can be
// easily generalized in the future.
assert(TI.getIntMaxTWidth() == 64);
DefineBuiltinMacro(Buf, "__INTMAX_MAX__=9223372036854775807LL");
if (TI.getIntMaxType() == TargetInfo::UnsignedLongLong)
DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=unsigned long long int");
else if (TI.getIntMaxType() == TargetInfo::SignedLongLong)
DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=long long int");
DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=int");
DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=long long unsigned int");
}
else if (TI.getIntMaxType() == TargetInfo::UnsignedLong)
DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=unsigned long int");
else if (TI.getIntMaxType() == TargetInfo::SignedLong)
DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=long int");
else if (TI.getIntMaxType() == TargetInfo::UnsignedInt)
DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=unsigned int");
else
DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=int");
if (TI.getUIntMaxType() == TargetInfo::UnsignedLongLong)
DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=unsigned long long int");
else if (TI.getUIntMaxType() == TargetInfo::SignedLongLong)
DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=long long int");
else if (TI.getUIntMaxType() == TargetInfo::UnsignedLong)
DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=unsigned long int");
else if (TI.getUIntMaxType() == TargetInfo::SignedLong)
DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=long int");
else if (TI.getUIntMaxType() == TargetInfo::UnsignedInt)
DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=unsigned int");
else
DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=int");
if (TI.getPtrDiffType(0) == TargetInfo::UnsignedLongLong)
DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=unsigned long long int");
else if (TI.getPtrDiffType(0) == TargetInfo::SignedLongLong)
DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=long long int");
else if (TI.getPtrDiffType(0) == TargetInfo::UnsignedLong)
DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=unsigned long int");
else if (TI.getPtrDiffType(0) == TargetInfo::SignedLong)
DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=long int");
else if (TI.getPtrDiffType(0) == TargetInfo::UnsignedInt)
DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=unsigned int");
else
DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=int");
if (TI.getSizeType() == TargetInfo::UnsignedLongLong)
DefineBuiltinMacro(Buf, "__SIZE_TYPE__=unsigned long long int");
else if (TI.getSizeType() == TargetInfo::SignedLongLong)
DefineBuiltinMacro(Buf, "__SIZE_TYPE__=long long int");
else if (TI.getSizeType() == TargetInfo::UnsignedLong)
DefineBuiltinMacro(Buf, "__SIZE_TYPE__=unsigned long int");
else if (TI.getSizeType() == TargetInfo::SignedLong)
DefineBuiltinMacro(Buf, "__SIZE_TYPE__=long int");
else if (TI.getSizeType() == TargetInfo::UnsignedInt)
DefineBuiltinMacro(Buf, "__SIZE_TYPE__=unsigned int");
else if (TI.getSizeType() == TargetInfo::SignedInt)
DefineBuiltinMacro(Buf, "__SIZE_TYPE__=int");
else
DefineBuiltinMacro(Buf, "__SIZE_TYPE__=unsigned short");
// All of our current targets have sizeof(long) == sizeof(void*).
assert(TI.getPointerWidth(0) == TI.getLongWidth());
DefineBuiltinMacro(Buf, "__SIZE_TYPE__=long unsigned int");
DefineFloatMacros(Buf, "FLT", &TI.getFloatFormat());
DefineFloatMacros(Buf, "DBL", &TI.getDoubleFormat());
DefineFloatMacros(Buf, "LDBL", &TI.getLongDoubleFormat());
@ -612,7 +640,6 @@ static void InitializePredefinedMacros(Preprocessor &PP,
Buf.push_back('\n');
}
char MacroBuf[60];
if (const char *Prefix = TI.getUserLabelPrefix()) {
sprintf(MacroBuf, "__USER_LABEL_PREFIX__=%s", Prefix);
DefineBuiltinMacro(Buf, MacroBuf);

View File

@ -551,9 +551,9 @@ Parser::DeclTy *Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS) {
///
void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,
unsigned TagType, DeclTy *TagDecl) {
assert(TagType == DeclSpec::TST_struct ||
assert((TagType == DeclSpec::TST_struct ||
TagType == DeclSpec::TST_union ||
TagType == DeclSpec::TST_class && "Invalid TagType!");
TagType == DeclSpec::TST_class) && "Invalid TagType!");
SourceLocation LBraceLoc = ConsumeBrace();
@ -626,8 +626,8 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,
// For a local class of inline method, pop the LexedMethodsForTopClass that
// was previously pushed.
assert(CurScope->isInCXXInlineMethodScope() ||
TopClassStacks.size() == 1 &&
assert((CurScope->isInCXXInlineMethodScope() ||
TopClassStacks.size() == 1) &&
"MethodLexers not getting popped properly!");
if (CurScope->isInCXXInlineMethodScope())
PopTopClassStack();

View File

@ -453,7 +453,7 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D,
if (!Member) return LastInGroup;
assert(II || isInstField && "No identifier for non-field ?");
assert((II || isInstField) && "No identifier for non-field ?");
// set/getAccess is not part of Decl's interface to avoid bloating it with C++
// specific methods. Use a wrapper class that can be used with all C++ class