[cfe-dev] LValueExprEvaluator::VisitArraySubscriptExpr assertion

Stephan Bergmann sbergman at redhat.com
Wed Mar 25 02:48:09 PDT 2015


In LibreOffice we have a Clang plugin calling 
Expr::EvaluateAsBooleanCondition, and at least with a recent trunk Clang 
build with assertions enabled that triggers the assert in

> static bool EvaluatePointer(const Expr* E, LValue& Result, EvalInfo &Info) {
>   assert(E->isRValue() && E->getType()->hasPointerRepresentation());
>   return PointerExprEvaluator(Info, Result).Visit(E);
> }

(in lib/AST/ExprConstant.cpp) on expressions like

   m_Strings[nEntry]

where m_Strings is of std::vector type.

What happens is that Expr::EvaluateAsBooleanCondition goes into 
LValueExprEvaluator::VisitArraySubscriptExpr, which calls 
EvaluatePointer, which asserts because m_Strings doesn't have array or 
pointer type.

It's not clear to me where the error lies; should 
LValueExprEvaluator::VisitArraySubscriptExpr even be reached for uses of 
user-defined operator[] overloads?

For now, I'm working around the assertion with

> Index: lib/AST/ExprConstant.cpp
> ===================================================================
> --- lib/AST/ExprConstant.cpp	(revision 233173)
> +++ lib/AST/ExprConstant.cpp	(working copy)
> @@ -4647,6 +4647,10 @@
>    if (E->getBase()->getType()->isVectorType())
>      return Error(E);
>
> +  if (!(E->getBase()->getType()->isArrayType() ||
> +        E->getBase()->getType()->isPointerType()))
> +    return false;
> +
>    if (!EvaluatePointer(E->getBase(), Result, Info))
>      return false;
>



More information about the cfe-dev mailing list