forked from OSchip/llvm-project
Implement MS _ReturnAddress and _AddressOfReturnAddress intrinsics
Reviewers: rnk, thakis, majnemer, hans Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D25540 llvm-svn: 284131
This commit is contained in:
parent
468e793fea
commit
397d81bb9a
|
@ -753,6 +753,7 @@ LANGBUILTIN(__popcnt16, "UsUs", "nc", ALL_MS_LANGUAGES)
|
|||
LANGBUILTIN(__popcnt, "UiUi", "nc", ALL_MS_LANGUAGES)
|
||||
LANGBUILTIN(__popcnt64, "ULLiULLi", "nc", ALL_MS_LANGUAGES)
|
||||
LANGBUILTIN(__readfsdword, "ULiULi", "n", ALL_MS_LANGUAGES)
|
||||
LANGBUILTIN(_ReturnAddress, "v*", "n", ALL_MS_LANGUAGES)
|
||||
LANGBUILTIN(_rotl8, "UcUcUc", "n", ALL_MS_LANGUAGES)
|
||||
LANGBUILTIN(_rotl16, "UsUsUc", "n", ALL_MS_LANGUAGES)
|
||||
LANGBUILTIN(_rotl, "UiUii", "n", ALL_MS_LANGUAGES)
|
||||
|
|
|
@ -2039,6 +2039,8 @@ TARGET_HEADER_BUILTIN(_WriteBarrier, "v", "nh", "intrin.h", ALL_MS_LANGUAGES
|
|||
TARGET_HEADER_BUILTIN(__emul, "LLiii", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
|
||||
TARGET_HEADER_BUILTIN(__emulu, "ULLiUiUi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
|
||||
|
||||
TARGET_HEADER_BUILTIN(_AddressOfReturnAddress, "v*", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
|
||||
|
||||
#undef BUILTIN
|
||||
#undef TARGET_BUILTIN
|
||||
#undef TARGET_HEADER_BUILTIN
|
||||
|
|
|
@ -1147,6 +1147,10 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
|
|||
Value *F = CGM.getIntrinsic(Intrinsic::returnaddress);
|
||||
return RValue::get(Builder.CreateCall(F, Depth));
|
||||
}
|
||||
case Builtin::BI_ReturnAddress: {
|
||||
Value *F = CGM.getIntrinsic(Intrinsic::returnaddress);
|
||||
return RValue::get(Builder.CreateCall(F, Builder.getInt32(0)));
|
||||
}
|
||||
case Builtin::BI__builtin_frame_address: {
|
||||
Value *Depth =
|
||||
CGM.EmitConstantExpr(E->getArg(0), getContext().UnsignedIntTy, this);
|
||||
|
@ -7697,6 +7701,10 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
|
|||
case X86::BI_BitScanReverse:
|
||||
case X86::BI_BitScanReverse64:
|
||||
return EmitMSVCBuiltinExpr(MSVCIntrin::_BitScanReverse, E);
|
||||
case X86::BI_AddressOfReturnAddress: {
|
||||
Value *F = CGM.getIntrinsic(Intrinsic::addressofreturnaddress);
|
||||
return Builder.CreateCall(F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1112,14 +1112,6 @@ __stosq(unsigned __int64 *__dst, unsigned __int64 __x, size_t __n) {
|
|||
/*----------------------------------------------------------------------------*\
|
||||
|* Misc
|
||||
\*----------------------------------------------------------------------------*/
|
||||
static __inline__ void * __DEFAULT_FN_ATTRS
|
||||
_AddressOfReturnAddress(void) {
|
||||
return (void*)((char*)__builtin_frame_address(0) + sizeof(void*));
|
||||
}
|
||||
static __inline__ void * __DEFAULT_FN_ATTRS
|
||||
_ReturnAddress(void) {
|
||||
return __builtin_return_address(0);
|
||||
}
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
static __inline__ void __DEFAULT_FN_ATTRS
|
||||
__cpuid(int __info[4], int __level) {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
// RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \
|
||||
// RUN: -triple i686--windows -Oz -emit-llvm %s -o - \
|
||||
// RUN: | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-I386
|
||||
// RUN: | FileCheck %s -check-prefixes CHECK,CHECK-I386,CHECK-INTEL
|
||||
// RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \
|
||||
// RUN: -triple thumbv7--windows -Oz -emit-llvm %s -o - \
|
||||
// RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-ARM-X64
|
||||
// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-ARM-X64
|
||||
// RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \
|
||||
// RUN: -triple x86_64--windows -Oz -emit-llvm %s -o - \
|
||||
// RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-X64 --check-prefix=CHECK-ARM-X64
|
||||
// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-X64,CHECK-ARM-X64,CHECK-INTEL
|
||||
|
||||
// intrin.h needs size_t, but -ffreestanding prevents us from getting it from
|
||||
// stddef.h. Work around it with this typedef.
|
||||
|
@ -14,6 +14,22 @@ typedef __SIZE_TYPE__ size_t;
|
|||
|
||||
#include <intrin.h>
|
||||
|
||||
void *test_ReturnAddress() {
|
||||
return _ReturnAddress();
|
||||
}
|
||||
// CHECK-LABEL: define{{.*}}i8* @test_ReturnAddress()
|
||||
// CHECK: = tail call i8* @llvm.returnaddress(i32 0)
|
||||
// CHECK: ret i8*
|
||||
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
void *test_AddressOfReturnAddress() {
|
||||
return _AddressOfReturnAddress();
|
||||
}
|
||||
// CHECK-INTEL-LABEL: define i8* @test_AddressOfReturnAddress()
|
||||
// CHECK-INTEL: = tail call i8* @llvm.addressofreturnaddress()
|
||||
// CHECK-INTEL: ret i8*
|
||||
#endif
|
||||
|
||||
unsigned char test_BitScanForward(unsigned long *Index, unsigned long Mask) {
|
||||
return _BitScanForward(Index, Mask);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue