[PATCH] Have HasSideEffects() return false for __attribute__((const)) functions
Richard Smith
richard at metafoo.co.uk
Sun Apr 5 13:26:50 PDT 2015
================
Comment at: lib/AST/Expr.cpp:2953
@@ +2952,3 @@
+ const Decl *FD = cast<CallExpr>(this)->getCalleeDecl();
+ bool IsConst = FD && FD->hasAttr<ConstAttr>();
+ if (IsConst || !IncludePossibleEffects)
----------------
hfinkel wrote:
> You're checking for ConstAttr here, which is fine, but I think that we can do more:
>
> This is allowed:
> static int i;
> void foo() {
> __builtin_assume(i > 0);
> }
>
> and so we can also check for PureAttr. And what about constexpr functions?
>
I don't think we can do anything interesting for `constexpr` functions, because they're not pure in general. One thing you could do is to try to evaluate the expression; if it's a constant expression, then it has no side-effects.
http://reviews.llvm.org/D8548
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
More information about the cfe-commits
mailing list