]> granicus.if.org Git - clang/commitdiff
Add a couple of assertions to make sure the bitfields can fit the value assigned...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 30 Apr 2011 02:28:27 +0000 (02:28 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 30 Apr 2011 02:28:27 +0000 (02:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130573 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h
include/clang/AST/Stmt.h

index ed207ace0c3121b6f74ebe20cc4ea5e6aeffcca4..f006f0ec6df8d153513ef601de6b51c0789a08aa 100644 (file)
@@ -2243,6 +2243,12 @@ private:
   }
   CXXBaseSpecifier **path_buffer();
 
+  void setBasePathSize(unsigned basePathSize) {
+    CastExprBits.BasePathSize = basePathSize;
+    assert(CastExprBits.BasePathSize == basePathSize &&
+           "basePathSize doesn't fit in bits of CastExprBits.BasePathSize!");
+  }
+
 protected:
   CastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
            const CastKind kind, Expr *op, unsigned BasePathSize) :
@@ -2258,14 +2264,14 @@ protected:
     Op(op) {
     assert(kind != CK_Invalid && "creating cast with invalid cast kind");
     CastExprBits.Kind = kind;
-    CastExprBits.BasePathSize = BasePathSize;
+    setBasePathSize(BasePathSize);
     CheckCastConsistency();
   }
 
   /// \brief Construct an empty cast.
   CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize)
     : Expr(SC, Empty) {
-    CastExprBits.BasePathSize = BasePathSize;
+    setBasePathSize(BasePathSize);
   }
 
 public:
index b368523eef8f6dbdc00becb55e14c24b6e8a1312..e3301c513a7c54065eb1ebcc82ed9b298d8798ec 100644 (file)
@@ -426,6 +426,8 @@ public:
                SourceLocation LB, SourceLocation RB)
   : Stmt(CompoundStmtClass), LBracLoc(LB), RBracLoc(RB) {
     CompoundStmtBits.NumStmts = NumStmts;
+    assert(CompoundStmtBits.NumStmts == NumStmts &&
+           "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!");
 
     if (NumStmts == 0) {
       Body = 0;