[cfe-dev] Constant expression checking rewrite

Eli Friedman eli.friedman at gmail.com
Fri May 16 14:20:08 PDT 2008


The other day, I ran into an annoying false positive in the constant
expression-checking code; that code has actually been annoying me for
a while, so I decided that the code needed to be replaced with some
more accurate checking.  Attached patch does this; it passes make
test, so it's at least mostly right.  It's also significantly stricter
about what it allows through as a constant expression, so it shouldn't
let through expressions that can't be codegen'ed properly.  The
implementation is complete in the sense that it follows all the C99
rules for constant expressions.

I'll put together some additional tests to cover some of the new cases
I'm checking before I commit.

I haven't really carefully considered the diagnostics yet; we probably
want more than just the generic "expression isn't constant" error, but
I'm not sure exactly what.  I've also marked some places that we might
want to warn in -pedantic mode with FIXMEs.  That said, the section
about constant expressions in C99 is a bit messy, and I'm not sure
what warnings are necessary/useful.

If Expr::isConstantExpr in the sense that it is currently implemented
is useful for outside code to query, I can refactor the code to
calculate it.  However, that will make things more complicated, and I
don't think we need it. Being a constant expression in the C99 sense
is not really an interesting property for any purpose I can think of.
Besides Sema, there are only a couple of other users in the current
codebase, and neither of them really want precisely what
Expr::isConstantExpr returns.

-Eli
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: t.txt
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080516/db35f83f/attachment.txt>


More information about the cfe-dev mailing list