]> granicus.if.org Git - clang/commitdiff
Fix a valgrind error noticed by Benoit Boissinot
authorChris Lattner <sabre@nondot.org>
Fri, 20 Jul 2007 18:48:28 +0000 (18:48 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 20 Jul 2007 18:48:28 +0000 (18:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40113 91177308-0d34-0410-b5e6-96231b3b80d8

AST/ASTContext.cpp
AST/Type.cpp
include/clang/AST/Type.h

index 29057b491ff76e36cba524bcf245e9c3de2847b2..3e1f32ded8a206c47fb14024f8dbad937d77a931 100644 (file)
@@ -565,7 +565,7 @@ QualType ASTContext::getFunctionType(QualType ResultTy, QualType *ArgArray,
   // variable size array (for parameter types) at the end of them.
   FunctionTypeProto *FTP = 
     (FunctionTypeProto*)malloc(sizeof(FunctionTypeProto) + 
-                               (NumArgs-1)*sizeof(QualType));
+                               NumArgs*sizeof(QualType));
   new (FTP) FunctionTypeProto(ResultTy, ArgArray, NumArgs, isVariadic,
                               Canonical);
   Types.push_back(FTP);
index e6aa6c8ae2a54c1e979c5520fefa4a1d765312c2..4e415e4ab6c96c5d9d71e47af586202b89c0eaec 100644 (file)
@@ -424,7 +424,7 @@ const char *BuiltinType::getName() const {
 }
 
 void FunctionTypeProto::Profile(llvm::FoldingSetNodeID &ID, QualType Result,
-                                QualType* ArgTys,
+                                arg_type_iterator ArgTys,
                                 unsigned NumArgs, bool isVariadic) {
   ID.AddPointer(Result.getAsOpaquePtr());
   for (unsigned i = 0; i != NumArgs; ++i)
@@ -433,7 +433,7 @@ void FunctionTypeProto::Profile(llvm::FoldingSetNodeID &ID, QualType Result,
 }
 
 void FunctionTypeProto::Profile(llvm::FoldingSetNodeID &ID) {
-  Profile(ID, getResultType(), ArgInfo, NumArgs, isVariadic());
+  Profile(ID, getResultType(), arg_type_begin(), NumArgs, isVariadic());
 }
 
 /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
index 1c2d9b6f60d329abda0f8330e31df19a1359897d..29472b4fe8e157bd2ca68a6ad0e4c48c899397dc 100644 (file)
@@ -563,6 +563,8 @@ class FunctionTypeProto : public FunctionType, public llvm::FoldingSetNode {
                     bool isVariadic, QualType Canonical)
     : FunctionType(FunctionProto, Result, isVariadic, Canonical),
       NumArgs(numArgs) {
+    // Fill in the trailing argument array.
+    QualType *ArgInfo = reinterpret_cast<QualType *>(this+1);;
     for (unsigned i = 0; i != numArgs; ++i)
       ArgInfo[i] = ArgArray[i];
   }
@@ -570,23 +572,23 @@ class FunctionTypeProto : public FunctionType, public llvm::FoldingSetNode {
   /// NumArgs - The number of arguments this function has, not counting '...'.
   unsigned NumArgs;
   
-  /// ArgInfo - This array holds the argument types.  Note that this is actually
-  /// a variable-sized array, so it must be the last instance variable in the
-  /// class.
-  QualType ArgInfo[1];
+  /// ArgInfo - There is an variable size array after the class in memory that
+  /// holds the argument types.
   friend class ASTContext;  // ASTContext creates these.
 public:
   unsigned getNumArgs() const { return NumArgs; }
   QualType getArgType(unsigned i) const {
     assert(i < NumArgs && "Invalid argument number!");
-    return ArgInfo[i];
+    return arg_type_begin()[i];
   }
     
   bool isVariadic() const { return getSubClassData(); }
   
   typedef const QualType *arg_type_iterator;
-  arg_type_iterator arg_type_begin() const { return ArgInfo; }
-  arg_type_iterator arg_type_end() const { return ArgInfo+NumArgs; }
+  arg_type_iterator arg_type_begin() const {
+    return reinterpret_cast<const QualType *>(this+1);
+  }
+  arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
   
   virtual void getAsStringInternal(std::string &InnerString) const;
 
@@ -597,7 +599,8 @@ public:
   
   void Profile(llvm::FoldingSetNodeID &ID);
   static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
-                      QualType* ArgTys, unsigned NumArgs, bool isVariadic);
+                      arg_type_iterator ArgTys, unsigned NumArgs,
+                      bool isVariadic);
 };