fortify: use __builtin_constant_p for more short-circuits
This also lets us retire our |__enable_if| version of |strlen|, which
should catch strictly fewer cases where we can fold the string's length
to a constant than |__builtin_constant_p| inside of |strlen|.
Bug: 131861088
Test: checkbuild on internal master. blueline bionic tests pass + it
boots.
Change-Id: I21b750a24f7d1825591a88d12a385be03a0a7ca3
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index b4ae393..42bf451 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -297,12 +297,21 @@
((bos_val) != __BIONIC_FORTIFY_UNKNOWN_SIZE && (bos_val) <= (val))
/* Intended for use in evaluated contexts. */
+#define __bos_dynamic_check_impl_and(bos_val, op, index, cond) \
+ (bos_val == __BIONIC_FORTIFY_UNKNOWN_SIZE || \
+ (__builtin_constant_p(index) && bos_val op index && (cond)))
+
#define __bos_dynamic_check_impl(bos_val, op, index) \
- (bos_val == __BIONIC_FORTIFY_UNKNOWN_SIZE || (__builtin_constant_p(index) && bos_val op index))
+ __bos_dynamic_check_impl_and(bos_val, op, index, 1)
+
+#define __bos_trivially_geq(bos_val, index) __bos_dynamic_check_impl((bos_val), >=, (index))
+
+#define __bos_trivially_gt(bos_val, index) __bos_dynamic_check_impl((bos_val), >, (index))
/* The names here are meant to match nicely with the __bos_unevaluated macros above. */
-#define __bos_trivially_not_lt(bos_val, index) __bos_dynamic_check_impl((bos_val), >=, (index))
-#define __bos_trivially_not_leq(bos_val, index) __bos_dynamic_check_impl((bos_val), >, (index))
+#define __bos_trivially_not_lt __bos_trivially_geq
+#define __bos_trivially_not_leq __bos_trivially_gt
+
#if defined(__BIONIC_FORTIFY) || defined(__BIONIC_DECLARE_FORTIFY_HELPERS)
# define __BIONIC_INCLUDE_FORTIFY_HEADERS 1