Bruno Haible wrote:

I like this wording.

OK, I merged that into the wording I proposed and installed the attached. One new point that I added is that I sometimes use 'assume (X)' to pacify GCC so that it does not issue a bogus warning in nearby code; this benefit of 'assume' is independent of the efficiency of the generated code.
From c882996026931d9b11b0878a9bb032ca6b3941dd Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Tue, 2 Jul 2019 16:33:04 -0700
Subject: [PATCH] =?UTF-8?q?verify:=20document=20=E2=80=98assume=E2=80=99?=
 =?UTF-8?q?=20better?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lib/verify.h: Reword doc (Bug#36370).
---
 ChangeLog    | 5 +++++
 lib/verify.h | 8 +++++---
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 77d8e9e6a..b89fd5d9e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2019-07-02  Paul Eggert  <egg...@cs.ucla.edu>
+
+       verify: document ‘assume’ better
+       * lib/verify.h: Reword doc (Bug#36370).
+
 2019-07-02  Bruno Haible  <br...@clisp.org>
 
        localcharset, nl_langinfo: Fix return value for UTF-8 locales on MSVC.
diff --git a/lib/verify.h b/lib/verify.h
index f8e4eff02..9b8e1ed20 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -259,9 +259,11 @@ template <int w>
 # define __has_builtin(x) 0
 #endif
 
-/* Assume that R always holds.  This lets the compiler optimize
-   accordingly.  R should not have side-effects; it may or may not be
-   evaluated.  Behavior is undefined if R is false.  */
+/* Assume that R always holds.  Behavior is undefined if R is false,
+   fails to evaluate, or has side effects.  Although assuming R can
+   help a compiler generate better code or diagnostics, performance
+   can suffer if R uses hard-to-optimize features such as function
+   calls not inlined by the compiler.  */
 
 #if (__has_builtin (__builtin_unreachable) \
      || 4 < __GNUC__ + (5 <= __GNUC_MINOR__))
-- 
2.17.1

Reply via email to