[PATCH] Have HasSideEffects() return false for __attribute__((const)) functions

Kuperstein, Michael M michael.m.kuperstein at intel.com
Mon Mar 23 09:27:14 PDT 2015


I think PureAttr isn't strong enough.

char foo(char *a)
{
   return *a;
}

is pure, but isn't side-effect free.

-----Original Message-----
From: hfinkel at anl.gov [mailto:hfinkel at anl.gov] 
Sent: Monday, March 23, 2015 18:20
To: Kuperstein, Michael M; richard at metafoo.co.uk; aaron.ballman at gmail.com; hfinkel at anl.gov
Cc: cfe-commits at cs.uiuc.edu
Subject: Re: [PATCH] Have HasSideEffects() return false for __attribute__((const)) functions

================
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)
----------------
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?

http://reviews.llvm.org/D8548

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/


---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.




More information about the cfe-commits mailing list