]> granicus.if.org Git - clang/commitdiff
Add an assertion that we don't overflow the bitfield ObjCMessageExpr::NumArgs.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 3 Oct 2011 06:36:40 +0000 (06:36 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 3 Oct 2011 06:36:40 +0000 (06:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140985 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ExprObjC.h
lib/AST/Expr.cpp

index 09449118678a7da6640b5f6a743586e4053b20f7..d141fda395d7bb09d5ddb5e63826c9c2c734a438 100644 (file)
@@ -444,9 +444,16 @@ private:
 /// class, and can be distinguished via \c getReceiverKind(). Example:
 ///
 class ObjCMessageExpr : public Expr {
+  enum { NumArgsBitWidth = 16 };
+
   /// \brief The number of arguments in the message send, not
   /// 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
   /// ReceiverKind values.
@@ -482,8 +489,10 @@ class ObjCMessageExpr : public Expr {
   SourceLocation LBracLoc, RBracLoc;
 
   ObjCMessageExpr(EmptyShell Empty, unsigned NumArgs)
-    : Expr(ObjCMessageExprClass, Empty), NumArgs(NumArgs), Kind(0), 
-      HasMethod(0), IsDelegateInitCall(0), SelectorOrMethod(0) { }
+    : Expr(ObjCMessageExprClass, Empty), Kind(0), 
+      HasMethod(0), IsDelegateInitCall(0), SelectorOrMethod(0) {
+    setNumArgs(NumArgs);
+  }
 
   ObjCMessageExpr(QualType T, ExprValueKind VK,
                   SourceLocation LBracLoc,
index 232709cb262cd907a84ddb363baf7ea303609739..b0f23f9717eb49dfe2ecb3156df029bccf76d0a8 100644 (file)
@@ -2724,12 +2724,13 @@ ObjCMessageExpr::ObjCMessageExpr(QualType T,
          /*TypeDependent=*/false, /*ValueDependent=*/false,
          /*InstantiationDependent=*/false,
          /*ContainsUnexpandedParameterPack=*/false),
-    NumArgs(NumArgs), Kind(IsInstanceSuper? SuperInstance : SuperClass),
+    Kind(IsInstanceSuper? SuperInstance : SuperClass),
     HasMethod(Method != 0), IsDelegateInitCall(false), SuperLoc(SuperLoc),
     SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method
                                                        : Sel.getAsOpaquePtr())),
     SelectorLoc(SelLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc) 
 {
+  setNumArgs(NumArgs);
   setReceiverPointer(SuperType.getAsOpaquePtr());
   if (NumArgs)
     memcpy(getArgs(), Args, NumArgs * sizeof(Expr *));
@@ -2747,12 +2748,13 @@ ObjCMessageExpr::ObjCMessageExpr(QualType T,
   : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, T->isDependentType(),
          T->isDependentType(), T->isInstantiationDependentType(),
          T->containsUnexpandedParameterPack()),
-    NumArgs(NumArgs), Kind(Class),
+    Kind(Class),
     HasMethod(Method != 0), IsDelegateInitCall(false),
     SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method
                                                        : Sel.getAsOpaquePtr())),
     SelectorLoc(SelLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc) 
 {
+  setNumArgs(NumArgs);
   setReceiverPointer(Receiver);
   Expr **MyArgs = getArgs();
   for (unsigned I = 0; I != NumArgs; ++I) {
@@ -2782,12 +2784,13 @@ ObjCMessageExpr::ObjCMessageExpr(QualType T,
          Receiver->isTypeDependent(),
          Receiver->isInstantiationDependent(),
          Receiver->containsUnexpandedParameterPack()),
-    NumArgs(NumArgs), Kind(Instance),
+    Kind(Instance),
     HasMethod(Method != 0), IsDelegateInitCall(false),
     SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method
                                                        : Sel.getAsOpaquePtr())),
     SelectorLoc(SelLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc) 
 {
+  setNumArgs(NumArgs);
   setReceiverPointer(Receiver);
   Expr **MyArgs = getArgs();
   for (unsigned I = 0; I != NumArgs; ++I) {