r231986 - Under duress, move check for target support of __builtin_setjmp/

Joerg Sonnenberger joerg at bec.de
Wed Mar 11 16:46:33 PDT 2015


Author: joerg
Date: Wed Mar 11 18:46:32 2015
New Revision: 231986

URL: http://llvm.org/viewvc/llvm-project?rev=231986&view=rev
Log:
Under duress, move check for target support of __builtin_setjmp/
__builtin_longjmp to Sema as requested by John McCall.

Added:
    cfe/trunk/test/Sema/builtin-longjmp.c
      - copied, changed from r231985, cfe/trunk/test/CodeGen/builtin-longjmp.c
Removed:
    cfe/trunk/test/CodeGen/builtin-longjmp.c
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/include/clang/Basic/TargetInfo.h
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/Basic/Targets.cpp
    cfe/trunk/lib/CodeGen/CGBuiltin.cpp
    cfe/trunk/lib/CodeGen/TargetInfo.cpp
    cfe/trunk/lib/CodeGen/TargetInfo.h
    cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=231986&r1=231985&r2=231986&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Mar 11 18:46:32 2015
@@ -7053,6 +7053,11 @@ def note_neon_vector_initializer_non_por
   "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">;

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=231986&r1=231985&r2=231986&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Wed Mar 11 18:46:32 2015
@@ -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:
   virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
     return PointerWidth;

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=231986&r1=231985&r2=231986&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Mar 11 18:46:32 2015
@@ -8556,6 +8556,7 @@ private:
   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);

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=231986&r1=231985&r2=231986&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Wed Mar 11 18:46:32 2015
@@ -981,6 +981,10 @@ public:
     if (RegNo == 1) return 4;
     return -1;
   }
+
+  bool hasSjLjLowering() const override {
+    return true;
+  }
 };
 
 const Builtin::Info PPCTargetInfo::BuiltinInfo[] = {
@@ -2271,6 +2275,10 @@ public:
   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) {

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=231986&r1=231985&r2=231986&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed Mar 11 18:46:32 2015
@@ -859,11 +859,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(
       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));
 
@@ -886,10 +881,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(
     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);
 

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=231986&r1=231985&r2=231986&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Wed Mar 11 18:46:32 2015
@@ -664,10 +664,6 @@ public:
                    ('T' << 24);
     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 {
     return HasAVX ? 32 : 16;
   }
-
-  bool hasSjLjLowering(CodeGen::CodeGenFunction &CGF) const override {
-    return true;
-  }
 };
 
 class PS4TargetCodeGenInfo : public X86_64TargetCodeGenInfo {
@@ -1724,10 +1716,6 @@ public:
   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,
@@ -3127,10 +3115,6 @@ public:
   unsigned getOpenMPSimdDefaultAlignment(QualType) const override {
     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.
   }
-
-  bool hasSjLjLowering(CodeGen::CodeGenFunction &CGF) const override {
-    return true;
-  }
 };
 
 class PPC64TargetCodeGenInfo : public DefaultTargetCodeGenInfo {
@@ -3402,10 +3382,6 @@ public:
   unsigned getOpenMPSimdDefaultAlignment(QualType) const override {
     return 16; // Natural alignment for Altivec vectors.
   }
-
-  bool hasSjLjLowering(CodeGen::CodeGenFunction &CGF) const override {
-    return true;
-  }
 };
 
 }
@@ -4533,12 +4509,6 @@ public:
                                               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 {

Modified: cfe/trunk/lib/CodeGen/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.h?rev=231986&r1=231985&r2=231986&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/TargetInfo.h (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.h Wed Mar 11 18:46:32 2015
@@ -225,12 +225,6 @@ public:
   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;
-  }
 };
 }
 

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=231986&r1=231985&r2=231986&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Mar 11 18:46:32 2015
@@ -319,6 +319,10 @@ Sema::CheckBuiltinFunctionCall(FunctionD
     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;
@@ -2457,8 +2461,13 @@ bool Sema::SemaBuiltinConstantArgRange(C
 }
 
 /// 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;
 
@@ -2473,6 +2482,16 @@ bool Sema::SemaBuiltinLongjmp(CallExpr *
   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,

Removed: cfe/trunk/test/CodeGen/builtin-longjmp.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtin-longjmp.c?rev=231985&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/builtin-longjmp.c (original)
+++ cfe/trunk/test/CodeGen/builtin-longjmp.c (removed)
@@ -1,34 +0,0 @@
-// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm < %s| FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm < %s| FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-windows -emit-llvm < %s| FileCheck %s
-// RUN: %clang_cc1 -triple powerpc-unknown-unknown -emit-llvm < %s| FileCheck %s
-// RUN: %clang_cc1 -triple powerpc64-unknown-unknown -emit-llvm < %s| FileCheck %s
-
-// RUN: %clang_cc1 -triple arm-unknown-unknown -emit-llvm-only -verify %s
-// RUN: %clang_cc1 -triple aarch64-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
-
-// Check that __builtin_longjmp and __builtin_setjmp are lowerd into
-// IR intrinsics on those architectures that can handle them.
-// Check that they are lowered to the libcalls on other architectures.
-
-typedef void *jmp_buf;
-jmp_buf buf;
-
-// CHECK:   define{{.*}} void @do_jump()
-// CHECK:   call{{.*}} void @llvm.eh.sjlj.longjmp
-
-// CHECK:   define{{.*}} void @do_setjmp()
-// CHECK:   call{{.*}} i32 @llvm.eh.sjlj.setjmp
-
-void do_jump(void) {
-  __builtin_longjmp(buf, 1); // expected-error {{cannot compile this __builtin_longjmp yet}}
-}
-
-void f(void);
-
-void do_setjmp(void) {
-  if (!__builtin_setjmp(buf))
-    f();
-}

Copied: cfe/trunk/test/Sema/builtin-longjmp.c (from r231985, cfe/trunk/test/CodeGen/builtin-longjmp.c)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/builtin-longjmp.c?p2=cfe/trunk/test/Sema/builtin-longjmp.c&p1=cfe/trunk/test/CodeGen/builtin-longjmp.c&r1=231985&r2=231986&rev=231986&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/builtin-longjmp.c (original)
+++ cfe/trunk/test/Sema/builtin-longjmp.c Wed Mar 11 18:46:32 2015
@@ -9,9 +9,9 @@
 // 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;
@@ -23,12 +23,12 @@ 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();
 }





More information about the cfe-commits mailing list