[libcxx-commits] [PATCH] D122397: [libc++] Use __builtin_expect and __builtin_assume in _LIBCPP_ASSERT

Mark de Wever via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Mar 24 12:56:43 PDT 2022


Mordante added a comment.

In D122397#3406340 <https://reviews.llvm.org/D122397#3406340>, @philnik wrote:

> `__builtin_assume` seems to ignore most of our asserts, but it definitely doesn't hurt. (https://godbolt.org/z/W7Gb43cx5). LGTM.

It might hurt when the assertion is wrong and the user builds without assertions.
https://godbolt.org/z/hsxhr9bWY
`test1` validates the pointer and `test2` doesn't since we told the compiler the if is always true.

Note that I'm not against doing this. I only wonder whether or not we need an opt-out for vendors/users.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122397/new/

https://reviews.llvm.org/D122397



More information about the libcxx-commits mailing list