[libc-commits] [libc] [libc][arm] implement setjmp/longjmp (PR #93220)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Thu May 23 11:06:06 PDT 2024


================
@@ -0,0 +1,31 @@
+
+//===-- Implementation of longjmp -----------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/setjmp/longjmp.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/properties/architectures.h"
+
+#if !defined(LIBC_TARGET_ARCH_IS_ARM)
+#error "Invalid file include"
+#endif
+
+namespace LIBC_NAMESPACE {
+
+[[gnu::naked]]
+LLVM_LIBC_FUNCTION(void, longjmp, (__jmp_buf * buf, int val)) {
+  asm("ldm.w r0!, {r4, r5, r6, r7, r8, r9, r10, r11, r12, lr}\n\t"
----------------
nickdesaulniers wrote:

> I think the norm is to use __asm__.

Ugly. No.

> Consider using a raw string with natural newlines.

Ah, good idea. 96d8f14ca1e83bc6af942a70b5a30fd410a67266

> The syntax allows {r4-r12, lr} which IMHO is more readable.
> It's unusual to use the .w suffix rather than letting the assembler decide what encoding to use. I'd just use ldm r0, {r4-r12, lr} here.

96d8f14ca1e83bc6af942a70b5a30fd410a67266

https://github.com/llvm/llvm-project/pull/93220


More information about the libc-commits mailing list