Under duress, move check for target support of __builtin_setjmp/

__builtin_longjmp to Sema as requested by John McCall.

llvm-svn: 231986
This commit is contained in:
Joerg Sonnenberger 2015-03-11 23:46:32 +00:00
parent 3c2ea3106c
commit 27173288c2
9 changed files with 44 additions and 50 deletions

View File

@ -7053,6 +7053,11 @@ def note_neon_vector_initializer_non_portable_q : Note<
"vcombine_%0%1(vcreate_%0%1(), vcreate_%0%1()) to initialize from integer " "vcombine_%0%1(vcreate_%0%1(), vcreate_%0%1()) to initialize from integer "
"constants">; "constants">;
def err_builtin_longjmp_unsupported : Error<
"__builtin_longjmp is not supported for the current target">;
def err_builtin_setjmp_unsupported : Error<
"__builtin_setjmp is not supported for the current target">;
def err_builtin_longjmp_invalid_val : Error< def err_builtin_longjmp_invalid_val : Error<
"argument to __builtin_longjmp must be a constant 1">; "argument to __builtin_longjmp must be a constant 1">;
def err_builtin_requires_language : Error<"'%0' is only available in %1">; def err_builtin_requires_language : Error<"'%0' is only available in %1">;

View File

@ -859,6 +859,12 @@ public:
} }
} }
/// Controls if __builtin_longjmp / __builtin_setjmp can be lowered to
/// llvm.eh.sjlj.longjmp / llvm.eh.sjlj.setjmp.
virtual bool hasSjLjLowering() const {
return false;
}
protected: protected:
virtual uint64_t getPointerWidthV(unsigned AddrSpace) const { virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
return PointerWidth; return PointerWidth;

View File

@ -8556,6 +8556,7 @@ private:
bool SemaBuiltinAssume(CallExpr *TheCall); bool SemaBuiltinAssume(CallExpr *TheCall);
bool SemaBuiltinAssumeAligned(CallExpr *TheCall); bool SemaBuiltinAssumeAligned(CallExpr *TheCall);
bool SemaBuiltinLongjmp(CallExpr *TheCall); bool SemaBuiltinLongjmp(CallExpr *TheCall);
bool SemaBuiltinSetjmp(CallExpr *TheCall);
ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult); ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult);
ExprResult SemaAtomicOpsOverloaded(ExprResult TheCallResult, ExprResult SemaAtomicOpsOverloaded(ExprResult TheCallResult,
AtomicExpr::AtomicOp Op); AtomicExpr::AtomicOp Op);

View File

@ -981,6 +981,10 @@ public:
if (RegNo == 1) return 4; if (RegNo == 1) return 4;
return -1; return -1;
} }
bool hasSjLjLowering() const override {
return true;
}
}; };
const Builtin::Info PPCTargetInfo::BuiltinInfo[] = { const Builtin::Info PPCTargetInfo::BuiltinInfo[] = {
@ -2271,6 +2275,10 @@ public:
CallingConv getDefaultCallingConv(CallingConvMethodType MT) const override { CallingConv getDefaultCallingConv(CallingConvMethodType MT) const override {
return MT == CCMT_Member ? CC_X86ThisCall : CC_C; return MT == CCMT_Member ? CC_X86ThisCall : CC_C;
} }
bool hasSjLjLowering() const override {
return true;
}
}; };
bool X86TargetInfo::setFPMath(StringRef Name) { bool X86TargetInfo::setFPMath(StringRef Name) {

View File

@ -859,11 +859,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
return RValue::get(Builder.CreateZExt(Result, Int64Ty, "extend.zext")); return RValue::get(Builder.CreateZExt(Result, Int64Ty, "extend.zext"));
} }
case Builtin::BI__builtin_setjmp: { case Builtin::BI__builtin_setjmp: {
if (!getTargetHooks().hasSjLjLowering(*this)) {
CGM.ErrorUnsupported(E, "__builtin_setjmp");
return RValue::get(nullptr);
}
// Buffer is a void**. // Buffer is a void**.
Value *Buf = EmitScalarExpr(E->getArg(0)); Value *Buf = EmitScalarExpr(E->getArg(0));
@ -886,10 +881,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
return RValue::get(Builder.CreateCall(F, Buf)); return RValue::get(Builder.CreateCall(F, Buf));
} }
case Builtin::BI__builtin_longjmp: { case Builtin::BI__builtin_longjmp: {
if (!getTargetHooks().hasSjLjLowering(*this)) {
CGM.ErrorUnsupported(E, "__builtin_longjmp");
return RValue::get(nullptr);
}
Value *Buf = EmitScalarExpr(E->getArg(0)); Value *Buf = EmitScalarExpr(E->getArg(0));
Buf = Builder.CreateBitCast(Buf, Int8PtrTy); Buf = Builder.CreateBitCast(Buf, Int8PtrTy);

View File

@ -664,10 +664,6 @@ public:
('T' << 24); ('T' << 24);
return llvm::ConstantInt::get(CGM.Int32Ty, Sig); return llvm::ConstantInt::get(CGM.Int32Ty, Sig);
} }
bool hasSjLjLowering(CodeGen::CodeGenFunction &CGF) const override {
return true;
}
}; };
} }
@ -1613,10 +1609,6 @@ public:
unsigned getOpenMPSimdDefaultAlignment(QualType) const override { unsigned getOpenMPSimdDefaultAlignment(QualType) const override {
return HasAVX ? 32 : 16; return HasAVX ? 32 : 16;
} }
bool hasSjLjLowering(CodeGen::CodeGenFunction &CGF) const override {
return true;
}
}; };
class PS4TargetCodeGenInfo : public X86_64TargetCodeGenInfo { class PS4TargetCodeGenInfo : public X86_64TargetCodeGenInfo {
@ -1724,10 +1716,6 @@ public:
unsigned getOpenMPSimdDefaultAlignment(QualType) const override { unsigned getOpenMPSimdDefaultAlignment(QualType) const override {
return HasAVX ? 32 : 16; return HasAVX ? 32 : 16;
} }
bool hasSjLjLowering(CodeGen::CodeGenFunction &CGF) const override {
return true;
}
}; };
void WinX86_64TargetCodeGenInfo::SetTargetAttributes(const Decl *D, void WinX86_64TargetCodeGenInfo::SetTargetAttributes(const Decl *D,
@ -3127,10 +3115,6 @@ public:
unsigned getOpenMPSimdDefaultAlignment(QualType) const override { unsigned getOpenMPSimdDefaultAlignment(QualType) const override {
return 16; // Natural alignment for Altivec vectors. return 16; // Natural alignment for Altivec vectors.
} }
bool hasSjLjLowering(CodeGen::CodeGenFunction &CGF) const override {
return true;
}
}; };
} }
@ -3381,10 +3365,6 @@ public:
return 16; // Natural alignment for Altivec and VSX vectors. return 16; // Natural alignment for Altivec and VSX vectors.
} }
bool hasSjLjLowering(CodeGen::CodeGenFunction &CGF) const override {
return true;
}
}; };
class PPC64TargetCodeGenInfo : public DefaultTargetCodeGenInfo { class PPC64TargetCodeGenInfo : public DefaultTargetCodeGenInfo {
@ -3402,10 +3382,6 @@ public:
unsigned getOpenMPSimdDefaultAlignment(QualType) const override { unsigned getOpenMPSimdDefaultAlignment(QualType) const override {
return 16; // Natural alignment for Altivec vectors. return 16; // Natural alignment for Altivec vectors.
} }
bool hasSjLjLowering(CodeGen::CodeGenFunction &CGF) const override {
return true;
}
}; };
} }
@ -4533,12 +4509,6 @@ public:
llvm::AttributeSet::FunctionIndex, llvm::AttributeSet::FunctionIndex,
B)); B));
} }
bool hasSjLjLowering(CodeGen::CodeGenFunction &CGF) const override {
return false;
// FIXME: backend implementation too restricted, even on Darwin.
// return CGF.getTarget().getTriple().isOSDarwin();
}
}; };
class WindowsARMTargetCodeGenInfo : public ARMTargetCodeGenInfo { class WindowsARMTargetCodeGenInfo : public ARMTargetCodeGenInfo {

View File

@ -225,12 +225,6 @@ public:
virtual unsigned getOpenMPSimdDefaultAlignment(QualType Type) const { virtual unsigned getOpenMPSimdDefaultAlignment(QualType Type) const {
return 0; return 0;
} }
/// Control if __builtin_longjmp / __builtin_setjmp can be lowered to
/// llvm.eh.sjlj.longjmp / llvm.eh.sjlj.setjmp.
virtual bool hasSjLjLowering(CodeGen::CodeGenFunction &CGF) const {
return false;
}
}; };
} }

View File

@ -319,6 +319,10 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
if (SemaBuiltinLongjmp(TheCall)) if (SemaBuiltinLongjmp(TheCall))
return ExprError(); return ExprError();
break; break;
case Builtin::BI__builtin_setjmp:
if (SemaBuiltinSetjmp(TheCall))
return ExprError();
break;
case Builtin::BI__builtin_classify_type: case Builtin::BI__builtin_classify_type:
if (checkArgCount(*this, TheCall, 1)) return true; if (checkArgCount(*this, TheCall, 1)) return true;
@ -2457,8 +2461,13 @@ bool Sema::SemaBuiltinConstantArgRange(CallExpr *TheCall, int ArgNum,
} }
/// SemaBuiltinLongjmp - Handle __builtin_longjmp(void *env[5], int val). /// SemaBuiltinLongjmp - Handle __builtin_longjmp(void *env[5], int val).
/// This checks that val is a constant 1. /// This checks that the target supports __builtin_longjmp and
/// that val is a constant 1.
bool Sema::SemaBuiltinLongjmp(CallExpr *TheCall) { bool Sema::SemaBuiltinLongjmp(CallExpr *TheCall) {
if (!Context.getTargetInfo().hasSjLjLowering())
return Diag(TheCall->getLocStart(), diag::err_builtin_longjmp_unsupported)
<< SourceRange(TheCall->getLocStart(), TheCall->getLocEnd());
Expr *Arg = TheCall->getArg(1); Expr *Arg = TheCall->getArg(1);
llvm::APSInt Result; llvm::APSInt Result;
@ -2473,6 +2482,16 @@ bool Sema::SemaBuiltinLongjmp(CallExpr *TheCall) {
return false; return false;
} }
/// SemaBuiltinSetjmp - Handle __builtin_setjmp(void *env[5]).
/// This checks that the target supports __builtin_setjmp.
bool Sema::SemaBuiltinSetjmp(CallExpr *TheCall) {
if (!Context.getTargetInfo().hasSjLjLowering())
return Diag(TheCall->getLocStart(), diag::err_builtin_setjmp_unsupported)
<< SourceRange(TheCall->getLocStart(), TheCall->getLocEnd());
return false;
}
namespace { namespace {
enum StringLiteralCheckType { enum StringLiteralCheckType {
SLCT_NotALiteral, SLCT_NotALiteral,

View File

@ -9,9 +9,9 @@
// RUN: %clang_cc1 -triple mips-unknown-unknown -emit-llvm-only -verify %s // RUN: %clang_cc1 -triple mips-unknown-unknown -emit-llvm-only -verify %s
// RUN: %clang_cc1 -triple mips64-unknown-unknown -emit-llvm-only -verify %s // RUN: %clang_cc1 -triple mips64-unknown-unknown -emit-llvm-only -verify %s
// Check that __builtin_longjmp and __builtin_setjmp are lowerd into // Check that __builtin_longjmp and __builtin_setjmp are lowered into
// IR intrinsics on those architectures that can handle them. // IR intrinsics on those architectures that can handle them.
// Check that they are lowered to the libcalls on other architectures. // Check that an error is created otherwise.
typedef void *jmp_buf; typedef void *jmp_buf;
jmp_buf buf; jmp_buf buf;
@ -23,12 +23,12 @@ jmp_buf buf;
// CHECK: call{{.*}} i32 @llvm.eh.sjlj.setjmp // CHECK: call{{.*}} i32 @llvm.eh.sjlj.setjmp
void do_jump(void) { void do_jump(void) {
__builtin_longjmp(buf, 1); // expected-error {{cannot compile this __builtin_longjmp yet}} __builtin_longjmp(buf, 1); // expected-error {{__builtin_longjmp is not supported for the current target}}
} }
void f(void); void f(void);
void do_setjmp(void) { void do_setjmp(void) {
if (!__builtin_setjmp(buf)) if (!__builtin_setjmp(buf)) // expected-error {{__builtin_setjmp is not supported for the current target}}
f(); f();
} }