diff options
author | Sanjiv Gupta <sanjiv.gupta@microchip.com> | 2008-10-31 09:52:39 +0000 |
---|---|---|
committer | Sanjiv Gupta <sanjiv.gupta@microchip.com> | 2008-10-31 09:52:39 +0000 |
commit | 31fc07df7f0fc89ebf83ca05a20b29de45a7598d (patch) | |
tree | 7d952a94384a81825468b68d59b257c7fe8ac780 | |
parent | dd913e557628abadee5112cca90e339d25b9b398 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58501 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/TargetInfo.h | 22 | ||||
-rw-r--r-- | lib/Analysis/CFRefCount.cpp | 2 | ||||
-rw-r--r-- | lib/Basic/TargetInfo.cpp | 5 | ||||
-rw-r--r-- | lib/Basic/Targets.cpp | 14 | ||||
-rw-r--r-- | lib/CodeGen/CGDecl.cpp | 2 | ||||
-rw-r--r-- | lib/Lex/Preprocessor.cpp | 95 | ||||
-rw-r--r-- | lib/Parse/ParseDeclCXX.cpp | 8 | ||||
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 2 |
8 files changed, 104 insertions, 46 deletions
diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h index 0d990179ff..32c87434d9 100644 --- a/include/clang/Basic/TargetInfo.h +++ b/include/clang/Basic/TargetInfo.h @@ -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, diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index 87a6b38b87..25466cbf62 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -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) diff --git a/lib/Basic/TargetInfo.cpp b/lib/Basic/TargetInfo.cpp index 20692ba5b1..aa19928e5f 100644 --- a/lib/Basic/TargetInfo.cpp +++ b/lib/Basic/TargetInfo.cpp @@ -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; diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 020c7d47db..456c1f8f35 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -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; } diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp index fd2e357370..788beb4410 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/lib/CodeGen/CGDecl.cpp @@ -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(); diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index ed69e6f933..c8c64bf3da 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -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"); + 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"); + 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"); - 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"); - DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=long long int"); + else if (TI.getPtrDiffType(0) == TargetInfo::UnsignedInt) + DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=unsigned int"); + else DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=int"); - DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=long long unsigned int"); - } - // All of our current targets have sizeof(long) == sizeof(void*). - assert(TI.getPointerWidth(0) == TI.getLongWidth()); - DefineBuiltinMacro(Buf, "__SIZE_TYPE__=long unsigned 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"); + 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); diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 21c7d6f0fe..7d03c59113 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -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(); diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index d5b631252d..cd72272941 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -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 |