From: Paul Eggert Date: Sat, 23 May 2020 16:41:54 +0000 (-0700) Subject: verify: document ‘assume’ better X-Git-Tag: v1.0~4081 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=b2c8d02c9750f335549781d20fa37415c9a1edb3;p=gnulib.git verify: document ‘assume’ better * lib/verify.h (assume): Say it’s for static analysis, not dynamic. --- diff --git a/ChangeLog b/ChangeLog index a4473284c3..44450a3549 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2020-05-23 Paul Eggert + + verify: document ‘assume’ better + * lib/verify.h (assume): Say it’s for static analysis, not dynamic. + 2020-05-22 Asher Gordon gendocs: Clarify licenses for templates. diff --git a/lib/verify.h b/lib/verify.h index d9ab89a570..f109761270 100644 --- a/lib/verify.h +++ b/lib/verify.h @@ -277,10 +277,22 @@ template #endif /* 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. */ + fails to evaluate, or has side effects. + + 'assume (R)' is a directive from the programmer telling the + compiler that R is true so the compiler needn't generate code to + test R. This is why 'assume' is in verify.h: it's related to + static checking (in this case, static checking done by the + programmer), not dynamic checking. + + 'assume (R)' can affect compilation of all the code, not just code + that happens to be executed after the assume (R) is "executed". + For example, if the code mistakenly does 'assert (R); assume (R);' + the compiler is entitled to optimize away the 'assert (R)'. + + 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 _GL_HAS_BUILTIN_UNREACHABLE # define assume(R) ((R) ? (void) 0 : __builtin_unreachable ())