|
@@ -95,6 +95,10 @@ public:
|
|
|
/// \brief Returns the size of type source info data block for the given type.
|
|
|
static unsigned getFullDataSizeForType(QualType Ty);
|
|
|
|
|
|
+ /// \brief Returns the alignment of type source info data block for
|
|
|
+ /// the given type.
|
|
|
+ static unsigned getLocalAlignmentForType(QualType Ty);
|
|
|
+
|
|
|
/// \brief Get the type for which this source info wrapper provides
|
|
|
/// information.
|
|
|
QualType getType() const {
|
|
@@ -229,7 +233,11 @@ public:
|
|
|
}
|
|
|
|
|
|
UnqualTypeLoc getUnqualifiedLoc() const {
|
|
|
- return UnqualTypeLoc(getTypePtr(), Data);
|
|
|
+ unsigned align =
|
|
|
+ TypeLoc::getLocalAlignmentForType(QualType(getTypePtr(), 0));
|
|
|
+ uintptr_t dataInt = reinterpret_cast<uintptr_t>(Data);
|
|
|
+ dataInt = llvm::RoundUpToAlignment(dataInt, align);
|
|
|
+ return UnqualTypeLoc(getTypePtr(), reinterpret_cast<void*>(dataInt));
|
|
|
}
|
|
|
|
|
|
/// Initializes the local data of this type source info block to
|
|
@@ -250,10 +258,11 @@ public:
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- /// \brief Returns the size of the type source info data block.
|
|
|
- unsigned getFullDataSize() const {
|
|
|
- return getLocalDataSize() +
|
|
|
- getFullDataSizeForType(getType().getLocalUnqualifiedType());
|
|
|
+ /// \brief Returns the alignment of the type source info data block that is
|
|
|
+ /// specific to this type.
|
|
|
+ unsigned getLocalDataAlignment() const {
|
|
|
+ // We don't preserve any location information.
|
|
|
+ return 1;
|
|
|
}
|
|
|
|
|
|
private:
|
|
@@ -280,9 +289,6 @@ inline UnqualTypeLoc TypeLoc::getUnqualifiedLoc() const {
|
|
|
/// \tparam LocalData the structure type of local location data for
|
|
|
/// this type
|
|
|
///
|
|
|
-/// sizeof(LocalData) needs to be a multiple of sizeof(void*) or
|
|
|
-/// else the world will end.
|
|
|
-///
|
|
|
/// TypeLocs with non-constant amounts of local data should override
|
|
|
/// getExtraLocalDataSize(); getExtraLocalData() will then point to
|
|
|
/// this extra memory.
|
|
@@ -317,12 +323,16 @@ class ConcreteTypeLoc : public Base {
|
|
|
}
|
|
|
|
|
|
public:
|
|
|
- unsigned getLocalDataSize() const {
|
|
|
- return sizeof(LocalData) + asDerived()->getExtraLocalDataSize();
|
|
|
+ unsigned getLocalDataAlignment() const {
|
|
|
+ return std::max(llvm::alignOf<LocalData>(),
|
|
|
+ asDerived()->getExtraLocalDataAlignment());
|
|
|
}
|
|
|
- // Give a default implementation that's useful for leaf types.
|
|
|
- unsigned getFullDataSize() const {
|
|
|
- return asDerived()->getLocalDataSize() + getInnerTypeSize();
|
|
|
+ unsigned getLocalDataSize() const {
|
|
|
+ unsigned size = sizeof(LocalData);
|
|
|
+ unsigned extraAlign = asDerived()->getExtraLocalDataAlignment();
|
|
|
+ size = llvm::RoundUpToAlignment(size, extraAlign);
|
|
|
+ size += asDerived()->getExtraLocalDataSize();
|
|
|
+ return size;
|
|
|
}
|
|
|
|
|
|
TypeLoc getNextTypeLoc() const {
|
|
@@ -338,6 +348,10 @@ protected:
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+ unsigned getExtraLocalDataAlignment() const {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
LocalData *getLocalData() const {
|
|
|
return static_cast<LocalData*>(Base::Data);
|
|
|
}
|
|
@@ -346,11 +360,17 @@ protected:
|
|
|
/// local data that can't be captured in the Info (e.g. because it's
|
|
|
/// of variable size).
|
|
|
void *getExtraLocalData() const {
|
|
|
- return getLocalData() + 1;
|
|
|
+ unsigned size = sizeof(LocalData);
|
|
|
+ unsigned extraAlign = asDerived()->getExtraLocalDataAlignment();
|
|
|
+ size = llvm::RoundUpToAlignment(size, extraAlign);
|
|
|
+ return reinterpret_cast<char*>(Base::Data) + size;
|
|
|
}
|
|
|
|
|
|
void *getNonLocalData() const {
|
|
|
- return static_cast<char*>(Base::Data) + asDerived()->getLocalDataSize();
|
|
|
+ uintptr_t data = reinterpret_cast<uintptr_t>(Base::Data);
|
|
|
+ data += asDerived()->getLocalDataSize();
|
|
|
+ data = llvm::RoundUpToAlignment(data, getNextTypeAlign());
|
|
|
+ return reinterpret_cast<void*>(data);
|
|
|
}
|
|
|
|
|
|
struct HasNoInnerType {};
|
|
@@ -373,6 +393,18 @@ private:
|
|
|
return getInnerTypeLoc().getFullDataSize();
|
|
|
}
|
|
|
|
|
|
+ unsigned getNextTypeAlign() const {
|
|
|
+ return getNextTypeAlign(asDerived()->getInnerType());
|
|
|
+ }
|
|
|
+
|
|
|
+ unsigned getNextTypeAlign(HasNoInnerType _) const {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ unsigned getNextTypeAlign(QualType T) const {
|
|
|
+ return TypeLoc::getLocalAlignmentForType(T);
|
|
|
+ }
|
|
|
+
|
|
|
TypeLoc getNextTypeLoc(HasNoInnerType _) const {
|
|
|
return TypeLoc();
|
|
|
}
|
|
@@ -417,7 +449,8 @@ class TypeSpecTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
|
|
|
Type,
|
|
|
TypeSpecLocInfo> {
|
|
|
public:
|
|
|
- enum { LocalDataSize = sizeof(TypeSpecLocInfo) };
|
|
|
+ enum { LocalDataSize = sizeof(TypeSpecLocInfo),
|
|
|
+ LocalDataAlignment = llvm::AlignOf<TypeSpecLocInfo>::Alignment };
|
|
|
|
|
|
SourceLocation getNameLoc() const {
|
|
|
return this->getLocalData()->NameLoc;
|
|
@@ -448,8 +481,6 @@ class BuiltinTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
|
|
|
BuiltinType,
|
|
|
BuiltinLocInfo> {
|
|
|
public:
|
|
|
- enum { LocalDataSize = sizeof(BuiltinLocInfo) };
|
|
|
-
|
|
|
SourceLocation getBuiltinLoc() const {
|
|
|
return getLocalData()->BuiltinLoc;
|
|
|
}
|
|
@@ -478,6 +509,10 @@ public:
|
|
|
return needsExtraLocalData() ? sizeof(WrittenBuiltinSpecs) : 0;
|
|
|
}
|
|
|
|
|
|
+ unsigned getExtraLocalDataAlignment() const {
|
|
|
+ return needsExtraLocalData() ? llvm::alignOf<WrittenBuiltinSpecs>() : 1;
|
|
|
+ }
|
|
|
+
|
|
|
SourceRange getLocalSourceRange() const {
|
|
|
return SourceRange(getBuiltinLoc(), getBuiltinLoc());
|
|
|
}
|
|
@@ -840,6 +875,10 @@ public:
|
|
|
return this->getNumProtocols() * sizeof(SourceLocation);
|
|
|
}
|
|
|
|
|
|
+ unsigned getExtraLocalDataAlignment() const {
|
|
|
+ return llvm::alignOf<SourceLocation>();
|
|
|
+ }
|
|
|
+
|
|
|
QualType getInnerType() const {
|
|
|
return getTypePtr()->getBaseType();
|
|
|
}
|
|
@@ -1166,6 +1205,10 @@ public:
|
|
|
return getNumArgs() * sizeof(ParmVarDecl*);
|
|
|
}
|
|
|
|
|
|
+ unsigned getExtraLocalDataAlignment() const {
|
|
|
+ return llvm::alignOf<ParmVarDecl*>();
|
|
|
+ }
|
|
|
+
|
|
|
QualType getInnerType() const { return getTypePtr()->getResultType(); }
|
|
|
};
|
|
|
|
|
@@ -1357,6 +1400,10 @@ public:
|
|
|
return getNumArgs() * sizeof(TemplateArgumentLocInfo);
|
|
|
}
|
|
|
|
|
|
+ unsigned getExtraLocalDataAlignment() const {
|
|
|
+ return llvm::alignOf<TemplateArgumentLocInfo>();
|
|
|
+ }
|
|
|
+
|
|
|
private:
|
|
|
TemplateArgumentLocInfo *getArgInfos() const {
|
|
|
return static_cast<TemplateArgumentLocInfo*>(getExtraLocalData());
|
|
@@ -1761,6 +1808,10 @@ public:
|
|
|
return getNumArgs() * sizeof(TemplateArgumentLocInfo);
|
|
|
}
|
|
|
|
|
|
+ unsigned getExtraLocalDataAlignment() const {
|
|
|
+ return llvm::alignOf<TemplateArgumentLocInfo>();
|
|
|
+ }
|
|
|
+
|
|
|
private:
|
|
|
TemplateArgumentLocInfo *getArgInfos() const {
|
|
|
return static_cast<TemplateArgumentLocInfo*>(getExtraLocalData());
|