public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/18487] New: Warnings for pure and const functions that are not actually pure or const
@ 2004-11-14 21:37 kazu at cs dot umass dot edu
  2004-11-14 21:57 ` [Bug tree-optimization/18487] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-11-14 21:37 UTC (permalink / raw)
  To: gcc-bugs

It would be nice if GCC can issue warnings for pure or const functions
that are not actually pure or const.

int foo (int) __attribute__ ((pure));
int bar (int) __attribute__ ((const));

int g;

int
foo (int a)
{
  g = a; /* A pure function is not supposed to write to memory.  */
  return 0;
}

int
bar (int a)
{
  return g; /* A const function is not supposed to read memory.  */
}

-- 
           Summary: Warnings for pure and const functions that are not
                    actually pure or const
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kazu at cs dot umass dot edu
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18487


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/18487] Warnings for pure and const functions that are not actually pure or const
  2004-11-14 21:37 [Bug tree-optimization/18487] New: Warnings for pure and const functions that are not actually pure or const kazu at cs dot umass dot edu
@ 2004-11-14 21:57 ` pinskia at gcc dot gnu dot org
  2004-11-16 22:44 ` dberlin at gcc dot gnu dot org
  2004-11-17  0:09 ` kazu at cs dot umass dot edu
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-11-14 21:57 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-11-14 21:57 -------
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |diagnostic
   Last reconfirmed|0000-00-00 00:00:00         |2004-11-14 21:57:50
               date|                            |
            Version|unknown                     |4.0.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18487


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/18487] Warnings for pure and const functions that are not actually pure or const
  2004-11-14 21:37 [Bug tree-optimization/18487] New: Warnings for pure and const functions that are not actually pure or const kazu at cs dot umass dot edu
  2004-11-14 21:57 ` [Bug tree-optimization/18487] " pinskia at gcc dot gnu dot org
@ 2004-11-16 22:44 ` dberlin at gcc dot gnu dot org
  2004-11-17  0:09 ` kazu at cs dot umass dot edu
  2 siblings, 0 replies; 4+ messages in thread
From: dberlin at gcc dot gnu dot org @ 2004-11-16 22:44 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dberlin at gcc dot gnu dot org  2004-11-16 22:43 -------
Actually, I think this is a remarkably bad idea, and would like to close this as
wontfix.

Pure and const are things that are not easily verifiable by the compiler in a
lot of common cases (it may get false negatives), and it's something the user is
affirmatively asserting.

In short, you shouldn't be saying it's pure or const if it's not pure or const.
If the compiler could tell whether you were right or not in all cases, you
wouldn't need the attributes in the first place.

False negatives appear commonly because left to it's own devices, no external
function could be marked pure or const by the compiler (because it has no idea
about what they do), and any function that called external functions could get
false negatives (because if the compiler couldn't rely on your assertions about
const or pure, these functions would also necessarily be not const or pure).
If the compiler is allowed to rely on your assertions when trying to verify it
for purposes of this warning, then the warning would miss cases where you got it
wrong anyway, because it would rely on your wrong assertion :P.

So basically, this is not something we can verify in anything but the most
trivial cases, we almost always end up relying on what the user tells us.   And
if the user is marking trivial functions const or pure when they clearly aren't,
they deserve what they get :).







-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |WAITING


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18487


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/18487] Warnings for pure and const functions that are not actually pure or const
  2004-11-14 21:37 [Bug tree-optimization/18487] New: Warnings for pure and const functions that are not actually pure or const kazu at cs dot umass dot edu
  2004-11-14 21:57 ` [Bug tree-optimization/18487] " pinskia at gcc dot gnu dot org
  2004-11-16 22:44 ` dberlin at gcc dot gnu dot org
@ 2004-11-17  0:09 ` kazu at cs dot umass dot edu
  2 siblings, 0 replies; 4+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-11-17  0:09 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From kazu at cs dot umass dot edu  2004-11-17 00:09 -------
This is hard.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|                            |WONTFIX


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18487


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-11-17  0:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-14 21:37 [Bug tree-optimization/18487] New: Warnings for pure and const functions that are not actually pure or const kazu at cs dot umass dot edu
2004-11-14 21:57 ` [Bug tree-optimization/18487] " pinskia at gcc dot gnu dot org
2004-11-16 22:44 ` dberlin at gcc dot gnu dot org
2004-11-17  0:09 ` kazu at cs dot umass dot edu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).