"vcombine_%0%1(vcreate_%0%1(), vcreate_%0%1()) to initialize from integer "
"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<
"argument to __builtin_longjmp must be a constant 1">;
def err_builtin_requires_language : Error<"'%0' is only available in %1">;
}
}
+ /// 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:
virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
return PointerWidth;
bool SemaBuiltinAssume(CallExpr *TheCall);
bool SemaBuiltinAssumeAligned(CallExpr *TheCall);
bool SemaBuiltinLongjmp(CallExpr *TheCall);
+ bool SemaBuiltinSetjmp(CallExpr *TheCall);
ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult);
ExprResult SemaAtomicOpsOverloaded(ExprResult TheCallResult,
AtomicExpr::AtomicOp Op);
if (RegNo == 1) return 4;
return -1;
}
+
+ bool hasSjLjLowering() const override {
+ return true;
+ }
};
const Builtin::Info PPCTargetInfo::BuiltinInfo[] = {
CallingConv getDefaultCallingConv(CallingConvMethodType MT) const override {
return MT == CCMT_Member ? CC_X86ThisCall : CC_C;
}
+
+ bool hasSjLjLowering() const override {
+ return true;
+ }
};
bool X86TargetInfo::setFPMath(StringRef Name) {
return RValue::get(Builder.CreateZExt(Result, Int64Ty, "extend.zext"));
}
case Builtin::BI__builtin_setjmp: {
- if (!getTargetHooks().hasSjLjLowering(*this)) {
- CGM.ErrorUnsupported(E, "__builtin_setjmp");
- return RValue::get(nullptr);
- }
-
// Buffer is a void**.
Value *Buf = EmitScalarExpr(E->getArg(0));
return RValue::get(Builder.CreateCall(F, Buf));
}
case Builtin::BI__builtin_longjmp: {
- if (!getTargetHooks().hasSjLjLowering(*this)) {
- CGM.ErrorUnsupported(E, "__builtin_longjmp");
- return RValue::get(nullptr);
- }
Value *Buf = EmitScalarExpr(E->getArg(0));
Buf = Builder.CreateBitCast(Buf, Int8PtrTy);
('T' << 24);
return llvm::ConstantInt::get(CGM.Int32Ty, Sig);
}
-
- bool hasSjLjLowering(CodeGen::CodeGenFunction &CGF) const override {
- return true;
- }
};
}
unsigned getOpenMPSimdDefaultAlignment(QualType) const override {
return HasAVX ? 32 : 16;
}
-
- bool hasSjLjLowering(CodeGen::CodeGenFunction &CGF) const override {
- return true;
- }
};
class PS4TargetCodeGenInfo : public X86_64TargetCodeGenInfo {
unsigned getOpenMPSimdDefaultAlignment(QualType) const override {
return HasAVX ? 32 : 16;
}
-
- bool hasSjLjLowering(CodeGen::CodeGenFunction &CGF) const override {
- return true;
- }
};
void WinX86_64TargetCodeGenInfo::SetTargetAttributes(const Decl *D,
unsigned getOpenMPSimdDefaultAlignment(QualType) const override {
return 16; // Natural alignment for Altivec vectors.
}
-
- bool hasSjLjLowering(CodeGen::CodeGenFunction &CGF) const override {
- return true;
- }
};
}
return 16; // Natural alignment for Altivec and VSX vectors.
}
-
- bool hasSjLjLowering(CodeGen::CodeGenFunction &CGF) const override {
- return true;
- }
};
class PPC64TargetCodeGenInfo : public DefaultTargetCodeGenInfo {
unsigned getOpenMPSimdDefaultAlignment(QualType) const override {
return 16; // Natural alignment for Altivec vectors.
}
-
- bool hasSjLjLowering(CodeGen::CodeGenFunction &CGF) const override {
- return true;
- }
};
}
llvm::AttributeSet::FunctionIndex,
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 {
virtual unsigned getOpenMPSimdDefaultAlignment(QualType Type) const {
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;
- }
};
}
if (SemaBuiltinLongjmp(TheCall))
return ExprError();
break;
+ case Builtin::BI__builtin_setjmp:
+ if (SemaBuiltinSetjmp(TheCall))
+ return ExprError();
+ break;
case Builtin::BI__builtin_classify_type:
if (checkArgCount(*this, TheCall, 1)) return true;
}
/// 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) {
+ if (!Context.getTargetInfo().hasSjLjLowering())
+ return Diag(TheCall->getLocStart(), diag::err_builtin_longjmp_unsupported)
+ << SourceRange(TheCall->getLocStart(), TheCall->getLocEnd());
+
Expr *Arg = TheCall->getArg(1);
llvm::APSInt Result;
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 {
enum StringLiteralCheckType {
SLCT_NotALiteral,
// RUN: %clang_cc1 -triple mips-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.
-// Check that they are lowered to the libcalls on other architectures.
+// Check that an error is created otherwise.
typedef void *jmp_buf;
jmp_buf buf;
// CHECK: call{{.*}} i32 @llvm.eh.sjlj.setjmp
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 do_setjmp(void) {
- if (!__builtin_setjmp(buf))
+ if (!__builtin_setjmp(buf)) // expected-error {{__builtin_setjmp is not supported for the current target}}
f();
}