On Apr 30, 2011, at 10:27 AM, Fariborz Jahanian wrote: > Doesn't this deserve a warning somewhere?
We do have a warning if you set a constant that overflows the bitfield. But the static analyzer doesn't seem to have a checker for that, submitted http://llvm.org/PR9821. > What can trigger this assertion? CastExprBits.BasePathSize is currently 11 bits so if you have more than 2048 base classes in your class there will be an assertion :-) -Argiris > > - Fariborz > > On Apr 29, 2011, at 7:28 PM, Argyrios Kyrtzidis wrote: > >> Author: akirtzidis >> Date: Fri Apr 29 21:28:27 2011 >> New Revision: 130573 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=130573&view=rev >> Log: >> Add a couple of assertions to make sure the bitfields can fit the value >> assigned to them. No functionality change. >> >> Modified: >> cfe/trunk/include/clang/AST/Expr.h >> cfe/trunk/include/clang/AST/Stmt.h >> >> Modified: cfe/trunk/include/clang/AST/Expr.h >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=130573&r1=130572&r2=130573&view=diff >> ============================================================================== >> --- cfe/trunk/include/clang/AST/Expr.h (original) >> +++ cfe/trunk/include/clang/AST/Expr.h Fri Apr 29 21:28:27 2011 >> @@ -2243,6 +2243,12 @@ >> } >> 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 @@ >> 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: >> >> Modified: cfe/trunk/include/clang/AST/Stmt.h >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=130573&r1=130572&r2=130573&view=diff >> ============================================================================== >> --- cfe/trunk/include/clang/AST/Stmt.h (original) >> +++ cfe/trunk/include/clang/AST/Stmt.h Fri Apr 29 21:28:27 2011 >> @@ -426,6 +426,8 @@ >> 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; >> >> >> _______________________________________________ >> cfe-commits mailing list >> [email protected] >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits > _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
