[cfe-commits] r40113 - in /cfe/trunk: AST/ASTContext.cpp AST/Type.cpp include/clang/AST/Type.h
Chris Lattner
sabre at nondot.org
Fri Jul 20 11:48:28 PDT 2007
Author: lattner
Date: Fri Jul 20 13:48:28 2007
New Revision: 40113
URL: http://llvm.org/viewvc/llvm-project?rev=40113&view=rev
Log:
Fix a valgrind error noticed by Benoit Boissinot
Modified:
cfe/trunk/AST/ASTContext.cpp
cfe/trunk/AST/Type.cpp
cfe/trunk/include/clang/AST/Type.h
Modified: cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/ASTContext.cpp?rev=40113&r1=40112&r2=40113&view=diff
==============================================================================
--- cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/trunk/AST/ASTContext.cpp Fri Jul 20 13:48:28 2007
@@ -565,7 +565,7 @@
// 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);
Modified: cfe/trunk/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Type.cpp?rev=40113&r1=40112&r2=40113&view=diff
==============================================================================
--- cfe/trunk/AST/Type.cpp (original)
+++ cfe/trunk/AST/Type.cpp Fri Jul 20 13:48:28 2007
@@ -424,7 +424,7 @@
}
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) {
- Profile(ID, getResultType(), ArgInfo, NumArgs, isVariadic());
+ Profile(ID, getResultType(), arg_type_begin(), NumArgs, isVariadic());
}
/// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=40113&r1=40112&r2=40113&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Fri Jul 20 13:48:28 2007
@@ -563,6 +563,8 @@
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 @@
/// 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 @@
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);
};
More information about the cfe-commits
mailing list