[cfe-commits] r58609 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp

Douglas Gregor doug.gregor at gmail.com
Mon Nov 3 06:12:50 PST 2008


Author: dgregor
Date: Mon Nov  3 08:12:49 2008
New Revision: 58609

URL: http://llvm.org/viewvc/llvm-project?rev=58609&view=rev
Log:
Connect ASTContext to TargetInfo when determining the size_t, ptrdiff_t, and wchar_t types. Fixes recent breakage on Linux.

Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/lib/AST/ASTContext.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=58609&r1=58608&r2=58609&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Mon Nov  3 08:12:49 2008
@@ -15,6 +15,7 @@
 #define LLVM_CLANG_AST_ASTCONTEXT_H
 
 #include "clang/Basic/LangOptions.h"
+#include "clang/Basic/TargetInfo.h"
 #include "clang/AST/Builtins.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/Type.h"
@@ -33,7 +34,6 @@
   class ASTRecordLayout;
   class Expr;
   class IdentifierTable;
-  class TargetInfo;
   class SelectorTable;
   class SourceManager;
   // Decls
@@ -319,6 +319,8 @@
   void setBuiltinVaListType(QualType T);
   QualType getBuiltinVaListType() const { return BuiltinVaListType; }
     
+  QualType getFromTargetType(TargetInfo::IntType Type) const;
+
   //===--------------------------------------------------------------------===//
   //                         Type Predicates.
   //===--------------------------------------------------------------------===//

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=58609&r1=58608&r2=58609&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon Nov  3 08:12:49 2008
@@ -1090,9 +1090,7 @@
 /// of the sizeof operator (C99 6.5.3.4p4). The value is target dependent and 
 /// needs to agree with the definition in <stddef.h>. 
 QualType ASTContext::getSizeType() const {
-  // On Darwin, size_t is defined as a "long unsigned int". 
-  // FIXME: should derive from "Target".
-  return UnsignedLongTy; 
+  return getFromTargetType(Target.getSizeType());
 }
 
 /// getWCharType - Return the unique type for "wchar_t" (C99 7.17), the
@@ -1102,9 +1100,9 @@
   if (LangOpts.CPlusPlus)
     return WCharTy;
 
-  // On Darwin, wchar_t is defined as a "int". 
-  // FIXME: should derive from "Target".
-  return IntTy; 
+  // FIXME: In C, shouldn't WCharTy just be a typedef of the target's
+  // wide-character type?
+  return getFromTargetType(Target.getWCharType());
 }
 
 /// getSignedWCharType - Return the type of "signed wchar_t".
@@ -1124,9 +1122,7 @@
 /// getPointerDiffType - Return the unique type for "ptrdiff_t" (ref?)
 /// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9).
 QualType ASTContext::getPointerDiffType() const {
-  // On Darwin, ptrdiff_t is defined as a "int". This seems like a bug...
-  // FIXME: should derive from "Target".
-  return IntTy; 
+  return getFromTargetType(Target.getPtrDiffType(0));
 }
 
 //===----------------------------------------------------------------------===//
@@ -1796,6 +1792,23 @@
   ObjCConstantStringType = getObjCInterfaceType(Decl);
 }
 
+/// getFromTargetType - Given one of the integer types provided by
+/// TargetInfo, produce the corresponding type.
+QualType ASTContext::getFromTargetType(TargetInfo::IntType Type) const {
+  switch (Type) {
+  case TargetInfo::NoInt: return QualType(); 
+  case TargetInfo::SignedShort: return ShortTy;
+  case TargetInfo::UnsignedShort: return UnsignedShortTy;
+  case TargetInfo::SignedInt: return IntTy;
+  case TargetInfo::UnsignedInt: return UnsignedIntTy;
+  case TargetInfo::SignedLong: return LongTy;
+  case TargetInfo::UnsignedLong: return UnsignedLongTy;
+  case TargetInfo::SignedLongLong: return LongLongTy;
+  case TargetInfo::UnsignedLongLong: return UnsignedLongLongTy;
+  }
+
+  assert(false && "Unhandled TargetInfo::IntType value");
+}
 
 //===----------------------------------------------------------------------===//
 //                        Type Predicates.





More information about the cfe-commits mailing list