[cfe-commits] r58501 - in /cfe/trunk: include/clang/Basic/TargetInfo.h lib/Analysis/CFRefCount.cpp lib/Basic/TargetInfo.cpp lib/Basic/Targets.cpp lib/CodeGen/CGDecl.cpp lib/Lex/Preprocessor.cpp lib/Parse/ParseDeclCXX.cpp lib/Sema/SemaDeclCXX.cpp
Sanjiv Gupta
sanjiv.gupta at microchip.com
Fri Oct 31 02:52:40 PDT 2008
Author: sgupta
Date: Fri Oct 31 04:52:39 2008
New Revision: 58501
URL: http://llvm.org/viewvc/llvm-project?rev=58501&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/Analysis/CFRefCount.cpp
cfe/trunk/lib/Basic/TargetInfo.cpp
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=58501&r1=58500&r2=58501&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Fri Oct 31 04:52:39 2008
@@ -58,6 +58,24 @@
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 @@
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,
Modified: cfe/trunk/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFRefCount.cpp?rev=58501&r1=58500&r2=58501&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Fri Oct 31 04:52:39 2008
@@ -1875,7 +1875,7 @@
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)
Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=58501&r1=58500&r2=58501&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/lib/Basic/TargetInfo.cpp Fri Oct 31 04:52:39 2008
@@ -34,6 +34,11 @@
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;
Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=58501&r1=58500&r2=58501&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Fri Oct 31 04:52:39 2008
@@ -801,11 +801,17 @@
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; }
Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=58501&r1=58500&r2=58501&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Fri Oct 31 04:52:39 2008
@@ -198,7 +198,7 @@
/// 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();
Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=58501&r1=58500&r2=58501&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Fri Oct 31 04:52:39 2008
@@ -553,9 +553,11 @@
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 @@
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 @@
Buf.push_back('\n');
}
- char MacroBuf[60];
if (const char *Prefix = TI.getUserLabelPrefix()) {
sprintf(MacroBuf, "__USER_LABEL_PREFIX__=%s", Prefix);
DefineBuiltinMacro(Buf, MacroBuf);
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=58501&r1=58500&r2=58501&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Fri Oct 31 04:52:39 2008
@@ -551,9 +551,9 @@
///
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 @@
// 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();
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=58501&r1=58500&r2=58501&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Oct 31 04:52:39 2008
@@ -453,7 +453,7 @@
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
More information about the cfe-commits
mailing list