[cfe-dev] Can't use sizeof ( typeof ( <vla> ))

Paulo Matos via cfe-dev cfe-dev at lists.llvm.org
Thu Nov 17 07:02:53 PST 2016


Hello,

Clang seems to be happy with most simple vla but then it crashes with:

int
f1 (int i)
{
  char a[i];
  return sizeof (typeof (a));
}

The assertion failure is :
clang-3.8:
/home/pmatos/Clients/embecosm/llvm/tools/clang/lib/CodeGen/CGExpr.cpp:2113:
clang::CodeGen::LValue
clang::CodeGen::CodeGenFunction::EmitDeclRefLValue(const
clang::DeclRefExpr*): Assertion `(ND->isUsed(false) || !isa<VarDecl>(ND)
|| !E->getLocation().isValid()) && "Should not use decl without marking
it used!"' failed.


Same issue with nightly.
I reported this as https://llvm.org/bugs/show_bug.cgi?id=31042

>From looking at the Sema code it looks like it just assumes that
anything inside sizeof () is unevaluated:
  enum ExpressionEvaluationContext {
    /// \brief The current expression and its subexpressions occur within an
    /// unevaluated operand (C++11 [expr]p7), such as the subexpression of
    /// \c sizeof, where the type of the expression may be significant but
    /// no code will be generated to evaluate the value of the expression at
    /// run time.
    Unevaluated,


The problem with this rationale is that it's not true in this case since
you need to evaluate typeof (a), which can't be evaluated at compile
time. Is it true that to fix this issue, we need to rethink how sizeof
are evaluated?

Kind regards,

-- 
Paulo Matos



More information about the cfe-dev mailing list