[cfe-commits] r140985 - in /cfe/trunk: include/clang/AST/ExprObjC.h lib/AST/Expr.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Sun Oct 2 23:36:40 PDT 2011


Author: akirtzidis
Date: Mon Oct  3 01:36:40 2011
New Revision: 140985

URL: http://llvm.org/viewvc/llvm-project?rev=140985&view=rev
Log:
Add an assertion that we don't overflow the bitfield ObjCMessageExpr::NumArgs.

Modified:
    cfe/trunk/include/clang/AST/ExprObjC.h
    cfe/trunk/lib/AST/Expr.cpp

Modified: cfe/trunk/include/clang/AST/ExprObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprObjC.h?rev=140985&r1=140984&r2=140985&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExprObjC.h (original)
+++ cfe/trunk/include/clang/AST/ExprObjC.h Mon Oct  3 01:36:40 2011
@@ -444,9 +444,16 @@
 /// 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 @@
   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,

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=140985&r1=140984&r2=140985&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Mon Oct  3 01:36:40 2011
@@ -2724,12 +2724,13 @@
          /*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 @@
   : 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 @@
          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) {





More information about the cfe-commits mailing list