[cfe-commits] r50197 - /cfe/trunk/lib/Analysis/BugReporter.cpp
Ted Kremenek
kremenek at apple.com
Wed Apr 23 16:36:07 PDT 2008
Wrong radar; this one: <rdar://problem/5879593>
On Apr 23, 2008, at 4:35 PM, Ted Kremenek wrote:
> Author: kremenek
> Date: Wed Apr 23 18:35:07 2008
> New Revision: 50197
>
> URL: http://llvm.org/viewvc/llvm-project?rev=50197&view=rev
> Log:
> For case statements involving enums, BugReporter now generates
> PathDiagnostics
> that say that we are jumping to "case a" instead of "case 0".
>
> This is a feature implementation for <rdar://problem/5880430>.
>
> Modified:
> cfe/trunk/lib/Analysis/BugReporter.cpp
>
> Modified: cfe/trunk/lib/Analysis/BugReporter.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BugReporter.cpp?rev=50197&r1=50196&r2=50197&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Analysis/BugReporter.cpp (original)
> +++ cfe/trunk/lib/Analysis/BugReporter.cpp Wed Apr 23 18:35:07 2008
> @@ -254,16 +254,16 @@
> case Stmt::SwitchStmtClass: {
>
> // Figure out what case arm we took.
> -
> - Stmt* S = Dst->getLabel();
> -
> - if (!S)
> - continue;
> -
> +
> std::ostringstream os;
> -
> - switch (S->getStmtClass()) {
> +
> + if (Stmt* S = Dst->getLabel())
> + switch (S->getStmtClass()) {
> +
> default:
> + assert(false && "Not a valid switch label.");
> + continue;
> +
> case Stmt::DefaultStmtClass: {
>
> os << "Control jumps to the 'default' case at line "
> @@ -276,38 +276,45 @@
>
> os << "Control jumps to 'case ";
>
> - Expr* CondE = cast<SwitchStmt>(T)->getCond();
> - unsigned bits = Ctx.getTypeSize(CondE->getType());
> + CaseStmt* Case = cast<CaseStmt>(S);
> + Expr* LHS = Case->getLHS()->IgnoreParenCasts();
>
> - llvm::APSInt V1(bits, false);
> + // Determine if it is an enum.
>
> - CaseStmt* Case = cast<CaseStmt>(S);
> + bool GetRawInt = true;
>
> - if (!Case->getLHS()->isIntegerConstantExpr(V1, Ctx,
> 0, true)) {
> - assert (false &&
> - "Case condition must evaluate to an integer
> constant.");
> - continue;
> + if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(LHS)) {
> +
> + // FIXME: Maybe this should be an assertion. Are
> there cases
> + // were it is not an EnumConstantDecl?
> +
> + EnumConstantDecl* D = dyn_cast<EnumConstantDecl>(DR-
> >getDecl());
> +
> + if (D) {
> + GetRawInt = false;
> + os << D->getName();
> + }
> }
> +
> + if (GetRawInt) {
>
> - os << V1.toString();
> -
> - // Get the RHS of the case, if it exists.
> -
> - if (Expr* E = Case->getRHS()) {
> -
> - llvm::APSInt V2(bits, false);
> + // Not an enum.
> + Expr* CondE = cast<SwitchStmt>(T)->getCond();
> + unsigned bits = Ctx.getTypeSize(CondE->getType());
> + llvm::APSInt V(bits, false);
>
> - if (!E->isIntegerConstantExpr(V2, Ctx, 0, true)) {
> - assert (false &&
> - "Case condition (RHS) must evaluate to an integer
> constant.");
> + if (!LHS->isIntegerConstantExpr(V, Ctx, 0, true)) {
> + assert (false && "Case condition must be
> constant.");
> continue;
> }
>
> - os << " .. " << V2.toString();
> + os << V.toString();
> }
>
> +
> +
> os << ":' at line "
> - << SMgr.getLogicalLineNumber(S->getLocStart()) << ".
> \n";
> + << SMgr.getLogicalLineNumber(S->getLocStart()) <<
> ".\n";
>
> break;
>
> @@ -381,10 +388,9 @@
> }
> }
> }
> - else
> - if (PathDiagnosticPiece* piece = R.VisitNode(N, NextNode,
> - *ReportGraph,
> *this))
> - PD.push_front(piece);
> +
> + if (PathDiagnosticPiece* p = R.VisitNode(N, NextNode,
> *ReportGraph, *this))
> + PD.push_front(p);
> }
> }
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list