This is an automated email from the ASF dual-hosted git repository.
kasjer pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new df01ae3d3 baselibc: Prevent optimization memset loop
df01ae3d3 is described below
commit df01ae3d30c131adb4befbc9e9d314a2d3d63a05
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Sat Jun 20 22:37:54 2026 +0200
baselibc: Prevent optimization memset loop
Modern compilers can detect that loop in this
function looks like something that can be replaced
by memset call.
It would lead to recursive call to itself.
With empty asm inline loop does not match pattern
that can be replace by memset call.
---
libc/baselibc/src/memset.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/libc/baselibc/src/memset.c b/libc/baselibc/src/memset.c
index 0cdaa6b2f..5b9da43ad 100644
--- a/libc/baselibc/src/memset.c
+++ b/libc/baselibc/src/memset.c
@@ -77,9 +77,15 @@ void *memset(void *dst, int c, size_t n)
:
:);
#else
- while (n--) {
- *q++ = c;
- }
+ while (n--) {
+ *q++ = c;
+ /*
+ * Blocks pattern matching, so this loop is not recognized
+ * as something that can be replaced by memset call
+ * that would result in recursion.
+ */
+ __asm__ volatile("" : : : "memory");
+ }
#endif
return dst;