// 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);
}
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)
}
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
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];
}
/// 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;
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);
};