Bug#123468: [Bug c/6906] warn about asserts with side effects

2020-04-16 Thread felix.von.s at posteo dot de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=6906

felix  changed:

   What|Removed |Added

 CC||felix.von.s at posteo dot de

--- Comment #9 from felix  ---
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.

-- 
You are receiving this mail because:
You reported the bug.


Bug#123468: [Bug c/6906] warn about asserts with side effects

2017-07-17 Thread felix.von.s at posteo dot de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=6906

felix  changed:

   What|Removed |Added

 CC||felix.von.s at posteo dot de

--- Comment #7 from felix  ---
What's wrong with the __builtin_pure_p approach? Sure, the diagnostics
generated by __attribute__((warning)) will be ugly, but it's still something.
It's also very simple to implement: it's just !TREE_SIDE_EFFECTS().

In fact, I patched my copy of GCC to add __builtin_pure_p defined just like
that and it seems to work fine. Might submit it soon (I didn't write any tests,
though).

-- 
You are receiving this mail because:
You reported the bug.