public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c/6906] warn about asserts with side effects [not found] <bug-6906-4@http.gcc.gnu.org/bugzilla/> @ 2020-04-16 17:43 ` felix.von.s at posteo dot de 0 siblings, 0 replies; 5+ messages in thread From: felix.von.s at posteo dot de @ 2020-04-16 17:43 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=6906 felix <felix.von.s at posteo dot de> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |felix.von.s at posteo dot de --- Comment #9 from felix <felix.von.s at posteo dot de> --- I have just realised that __builtin_pure_p is already expressible: #define __builtin_pure_p(expr) \ (__builtin_object_size(((void)(expr), ""), 2)) If (expr) is free of side effects, this is the same as __builtin_object_size("", 2), which is 1. Otherwise, the expression returns 0. This is documented behaviour, by the way. The documentation for __builtin_object_size at <https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html> states: > __builtin_object_size never evaluates its arguments for side effects. > If there are any side effects in them, it returns (size_t) -1 for > type 0 or 1 and (size_t) 0 for type 2 or 3. Experimentation reveals __attribute__((pure)) is enough for __builtin_object_size to consider a function free of side effects. ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <bug-6906-1490@http.gcc.gnu.org/bugzilla/>]
* [Bug c/6906] warn about asserts with side effects [not found] <bug-6906-1490@http.gcc.gnu.org/bugzilla/> @ 2006-10-15 19:45 ` pinskia at gcc dot gnu dot org 2008-03-03 2:56 ` chris dot pickett at mail dot mcgill dot ca 1 sibling, 0 replies; 5+ messages in thread From: pinskia at gcc dot gnu dot org @ 2006-10-15 19:45 UTC (permalink / raw) To: gcc-bugs ------- Comment #4 from pinskia at gcc dot gnu dot org 2006-10-15 19:45 ------- *** Bug 29480 has been marked as a duplicate of this bug. *** -- pinskia at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |robert at linuxfromscratch | |dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=6906 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/6906] warn about asserts with side effects [not found] <bug-6906-1490@http.gcc.gnu.org/bugzilla/> 2006-10-15 19:45 ` pinskia at gcc dot gnu dot org @ 2008-03-03 2:56 ` chris dot pickett at mail dot mcgill dot ca 1 sibling, 0 replies; 5+ messages in thread From: chris dot pickett at mail dot mcgill dot ca @ 2008-03-03 2:56 UTC (permalink / raw) To: gcc-bugs ------- Comment #5 from chris dot pickett at mail dot mcgill dot ca 2008-03-03 02:55 ------- Maybe you could fix the preprocessor to warn about operators with known side effects. Can cpp see the entire expr in assert (expr)? If so, just search the tokens for =, ++, --, +=, -=, etc. -- chris dot pickett at mail dot mcgill dot ca changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |chris dot pickett at mail | |dot mcgill dot ca http://gcc.gnu.org/bugzilla/show_bug.cgi?id=6906 ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <20020601163600.6906.123468@bugs.debian.org>]
* [Bug c/6906] warn about asserts with side effects [not found] <20020601163600.6906.123468@bugs.debian.org> @ 2003-12-31 17:20 ` pinskia at gcc dot gnu dot org 2004-08-10 23:56 ` mbp at sourcefrog dot net 1 sibling, 0 replies; 5+ messages in thread From: pinskia at gcc dot gnu dot org @ 2003-12-31 17:20 UTC (permalink / raw) To: gcc-bugs -- What |Removed |Added ---------------------------------------------------------------------------- Keywords| |diagnostic Last reconfirmed|2003-10-01 04:02:16 |2003-12-31 16:03:17 date| | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=6906 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/6906] warn about asserts with side effects [not found] <20020601163600.6906.123468@bugs.debian.org> 2003-12-31 17:20 ` pinskia at gcc dot gnu dot org @ 2004-08-10 23:56 ` mbp at sourcefrog dot net 1 sibling, 0 replies; 5+ messages in thread From: mbp at sourcefrog dot net @ 2004-08-10 23:56 UTC (permalink / raw) To: gcc-bugs ------- Additional Comments From mbp at sourcefrog dot net 2004-08-10 23:56 ------- It might be nice if there were a compile-time function similar to __builtin_constant_p which checked whether an expression was free of side-effects. One could then write # define assert(expr) \ (__builtin_pure_p((expr)) ? _real_assert(expr) : warning_assert_expr_not_pure()) So this would be true for things like __builtin_pure_p(arry[0] == 0) __builtin_pure_p(strlen(s) == 5) assuming the functions had the right attributes. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=6906 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-04-16 17:43 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <bug-6906-4@http.gcc.gnu.org/bugzilla/> 2020-04-16 17:43 ` [Bug c/6906] warn about asserts with side effects felix.von.s at posteo dot de [not found] <bug-6906-1490@http.gcc.gnu.org/bugzilla/> 2006-10-15 19:45 ` pinskia at gcc dot gnu dot org 2008-03-03 2:56 ` chris dot pickett at mail dot mcgill dot ca [not found] <20020601163600.6906.123468@bugs.debian.org> 2003-12-31 17:20 ` pinskia at gcc dot gnu dot org 2004-08-10 23:56 ` mbp at sourcefrog dot net
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).