Add an assertion that we don't overflow the bitfield ObjCMessageExpr::NumArgs.
llvm-svn: 140985
This commit is contained in:
parent
dfd6570643
commit
dc1244386f
|
@ -444,9 +444,16 @@ private:
|
||||||
/// class, and can be distinguished via \c getReceiverKind(). Example:
|
/// class, and can be distinguished via \c getReceiverKind(). Example:
|
||||||
///
|
///
|
||||||
class ObjCMessageExpr : public Expr {
|
class ObjCMessageExpr : public Expr {
|
||||||
|
enum { NumArgsBitWidth = 16 };
|
||||||
|
|
||||||
/// \brief The number of arguments in the message send, not
|
/// \brief The number of arguments in the message send, not
|
||||||
/// including the receiver.
|
/// including the receiver.
|
||||||
unsigned NumArgs : 16;
|
unsigned NumArgs : NumArgsBitWidth;
|
||||||
|
|
||||||
|
void setNumArgs(unsigned Num) {
|
||||||
|
assert((Num >> NumArgsBitWidth) == 0 && "Num of args is out of range!");
|
||||||
|
NumArgs = Num;
|
||||||
|
}
|
||||||
|
|
||||||
/// \brief The kind of message send this is, which is one of the
|
/// \brief The kind of message send this is, which is one of the
|
||||||
/// ReceiverKind values.
|
/// ReceiverKind values.
|
||||||
|
@ -482,8 +489,10 @@ class ObjCMessageExpr : public Expr {
|
||||||
SourceLocation LBracLoc, RBracLoc;
|
SourceLocation LBracLoc, RBracLoc;
|
||||||
|
|
||||||
ObjCMessageExpr(EmptyShell Empty, unsigned NumArgs)
|
ObjCMessageExpr(EmptyShell Empty, unsigned NumArgs)
|
||||||
: Expr(ObjCMessageExprClass, Empty), NumArgs(NumArgs), Kind(0),
|
: Expr(ObjCMessageExprClass, Empty), Kind(0),
|
||||||
HasMethod(0), IsDelegateInitCall(0), SelectorOrMethod(0) { }
|
HasMethod(0), IsDelegateInitCall(0), SelectorOrMethod(0) {
|
||||||
|
setNumArgs(NumArgs);
|
||||||
|
}
|
||||||
|
|
||||||
ObjCMessageExpr(QualType T, ExprValueKind VK,
|
ObjCMessageExpr(QualType T, ExprValueKind VK,
|
||||||
SourceLocation LBracLoc,
|
SourceLocation LBracLoc,
|
||||||
|
|
|
@ -2724,12 +2724,13 @@ ObjCMessageExpr::ObjCMessageExpr(QualType T,
|
||||||
/*TypeDependent=*/false, /*ValueDependent=*/false,
|
/*TypeDependent=*/false, /*ValueDependent=*/false,
|
||||||
/*InstantiationDependent=*/false,
|
/*InstantiationDependent=*/false,
|
||||||
/*ContainsUnexpandedParameterPack=*/false),
|
/*ContainsUnexpandedParameterPack=*/false),
|
||||||
NumArgs(NumArgs), Kind(IsInstanceSuper? SuperInstance : SuperClass),
|
Kind(IsInstanceSuper? SuperInstance : SuperClass),
|
||||||
HasMethod(Method != 0), IsDelegateInitCall(false), SuperLoc(SuperLoc),
|
HasMethod(Method != 0), IsDelegateInitCall(false), SuperLoc(SuperLoc),
|
||||||
SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method
|
SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method
|
||||||
: Sel.getAsOpaquePtr())),
|
: Sel.getAsOpaquePtr())),
|
||||||
SelectorLoc(SelLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc)
|
SelectorLoc(SelLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc)
|
||||||
{
|
{
|
||||||
|
setNumArgs(NumArgs);
|
||||||
setReceiverPointer(SuperType.getAsOpaquePtr());
|
setReceiverPointer(SuperType.getAsOpaquePtr());
|
||||||
if (NumArgs)
|
if (NumArgs)
|
||||||
memcpy(getArgs(), Args, NumArgs * sizeof(Expr *));
|
memcpy(getArgs(), Args, NumArgs * sizeof(Expr *));
|
||||||
|
@ -2747,12 +2748,13 @@ ObjCMessageExpr::ObjCMessageExpr(QualType T,
|
||||||
: Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, T->isDependentType(),
|
: Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, T->isDependentType(),
|
||||||
T->isDependentType(), T->isInstantiationDependentType(),
|
T->isDependentType(), T->isInstantiationDependentType(),
|
||||||
T->containsUnexpandedParameterPack()),
|
T->containsUnexpandedParameterPack()),
|
||||||
NumArgs(NumArgs), Kind(Class),
|
Kind(Class),
|
||||||
HasMethod(Method != 0), IsDelegateInitCall(false),
|
HasMethod(Method != 0), IsDelegateInitCall(false),
|
||||||
SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method
|
SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method
|
||||||
: Sel.getAsOpaquePtr())),
|
: Sel.getAsOpaquePtr())),
|
||||||
SelectorLoc(SelLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc)
|
SelectorLoc(SelLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc)
|
||||||
{
|
{
|
||||||
|
setNumArgs(NumArgs);
|
||||||
setReceiverPointer(Receiver);
|
setReceiverPointer(Receiver);
|
||||||
Expr **MyArgs = getArgs();
|
Expr **MyArgs = getArgs();
|
||||||
for (unsigned I = 0; I != NumArgs; ++I) {
|
for (unsigned I = 0; I != NumArgs; ++I) {
|
||||||
|
@ -2782,12 +2784,13 @@ ObjCMessageExpr::ObjCMessageExpr(QualType T,
|
||||||
Receiver->isTypeDependent(),
|
Receiver->isTypeDependent(),
|
||||||
Receiver->isInstantiationDependent(),
|
Receiver->isInstantiationDependent(),
|
||||||
Receiver->containsUnexpandedParameterPack()),
|
Receiver->containsUnexpandedParameterPack()),
|
||||||
NumArgs(NumArgs), Kind(Instance),
|
Kind(Instance),
|
||||||
HasMethod(Method != 0), IsDelegateInitCall(false),
|
HasMethod(Method != 0), IsDelegateInitCall(false),
|
||||||
SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method
|
SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method
|
||||||
: Sel.getAsOpaquePtr())),
|
: Sel.getAsOpaquePtr())),
|
||||||
SelectorLoc(SelLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc)
|
SelectorLoc(SelLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc)
|
||||||
{
|
{
|
||||||
|
setNumArgs(NumArgs);
|
||||||
setReceiverPointer(Receiver);
|
setReceiverPointer(Receiver);
|
||||||
Expr **MyArgs = getArgs();
|
Expr **MyArgs = getArgs();
|
||||||
for (unsigned I = 0; I != NumArgs; ++I) {
|
for (unsigned I = 0; I != NumArgs; ++I) {
|
||||||
|
|
Loading…
Reference in New Issue