Skip to content

Commit

Permalink
[AArch64] Add __builtin_sponentry, for calling setjmp in MinGW
Browse files Browse the repository at this point in the history
In MinGW, setjmp isn't expanded as a builtin in the compiler (like it
is for MSVC), but manually hooked up as calls to the right underlying
functions in headers. Using the actual CRT's real setjmp/longjmp
functions requires this intrinsic. (Currently this is worked around by
using MinGW specific reimplementations of setjmp/longjmp on aarch64.)

Differential Revision: https://reviews.llvm.org/D61592

llvm-svn: 360082
  • Loading branch information
mstorsjo authored and MrSidims committed May 17, 2019
1 parent c8eabf7 commit 356d784
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/BuiltinsAArch64.def
Expand Up @@ -86,6 +86,9 @@ LANGBUILTIN(__wfi, "v", "", ALL_MS_LANGUAGES)
LANGBUILTIN(__sev, "v", "", ALL_MS_LANGUAGES)
LANGBUILTIN(__sevl, "v", "", ALL_MS_LANGUAGES)

// Misc
BUILTIN(__builtin_sponentry, "v*", "c")

TARGET_HEADER_BUILTIN(_BitScanForward, "UcUNi*UNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
TARGET_HEADER_BUILTIN(_BitScanReverse, "UcUNi*UNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
TARGET_HEADER_BUILTIN(_BitScanForward64, "UcUNi*ULLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/CodeGen/CGBuiltin.cpp
Expand Up @@ -7233,6 +7233,11 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
return Builder.CreateCall(F);
}

if (BuiltinID == AArch64::BI__builtin_sponentry) {
llvm::Function *F = CGM.getIntrinsic(Intrinsic::sponentry);
return Builder.CreateCall(F);
}

// Find out if any arguments are required to be integer constant
// expressions.
unsigned ICEArguments = 0;
Expand Down
8 changes: 8 additions & 0 deletions clang/test/CodeGen/builtin-sponentry.c
@@ -0,0 +1,8 @@
// RUN: %clang_cc1 -triple aarch64-windows-gnu -Oz -emit-llvm %s -o - | FileCheck %s

void *test_sponentry() {
return __builtin_sponentry();
}
// CHECK-LABEL: define dso_local i8* @test_sponentry()
// CHECK: = tail call i8* @llvm.sponentry()
// CHECK: ret i8*

0 comments on commit 356d784

Please sign in to comment.