[llvm-branch-commits] [cfe-branch] r232028 - Merge r230255, 231245, 231280, 231986:

Joerg Sonnenberger joerg at bec.de
Thu Mar 12 04:14:45 PDT 2015


Author: joerg
Date: Thu Mar 12 06:14:45 2015
New Revision: 232028

URL: http://llvm.org/viewvc/llvm-project?rev=232028&view=rev
Log:
Merge r230255,231245,231280,231986:
Only lower __builtin_setjmp / __builtin_longjmp to
llvm.eh.sjlj.setjmp / llvm.eh.sjlj.longjmp, if the backend is known to
support them outside the Exception Handling context. The default
handling in LLVM codegen doesn't work and will create incorrect code.
The ARM backend on the other hand will assert if the intrinsics are
used.
--
Adjust the changes from r230255 to bail out if the backend can't lower
__builtin_setjmp/__builtin_longjmp and don't fall back to the libc
functions.
--
Fix test/CodeGen/builtins.c for platforms that don't lower sjlj

Opt in Win64 to supporting sjlj lowering. We have the backend lowering,
so I think this was just an oversight because WinX86_64TargetCodeGenInfo
doesn't inherit from X86_64TargetCodeGenInfo.
--
Under duress, move check for target support of __builtin_setjmp/
__builtin_longjmp to Sema as requested by John McCall.

Added:
    cfe/branches/release_36/test/Sema/builtin-longjmp.c
      - copied unchanged from r231986, cfe/trunk/test/Sema/builtin-longjmp.c
Removed:
    cfe/branches/release_36/test/CodeGen/2003-08-06-BuiltinSetjmpLongjmp.c
Modified:
    cfe/branches/release_36/   (props changed)
    cfe/branches/release_36/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/branches/release_36/include/clang/Basic/TargetInfo.h
    cfe/branches/release_36/include/clang/Sema/Sema.h
    cfe/branches/release_36/lib/Basic/Targets.cpp
    cfe/branches/release_36/lib/CodeGen/TargetInfo.cpp
    cfe/branches/release_36/lib/Sema/SemaChecking.cpp
    cfe/branches/release_36/test/CodeGen/builtins.c

Propchange: cfe/branches/release_36/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Mar 12 06:14:45 2015
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:226008,226049,226136,226282,226382,226384,226624,226707,226754,226863,226877,227062,227088,227220,227251,227278,227295,227368,227393,227861,227979,228053,228464,228785,228792,229408,229719
+/cfe/trunk:226008,226049,226136,226282,226382,226384,226624,226707,226754,226863,226877,227062,227088,227220,227251,227278,227295,227368,227393,227861,227979,228053,228464,228785,228792,229408,229719,230255,231245,231280,231986
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_36/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_36/include/clang/Basic/DiagnosticSemaKinds.td?rev=232028&r1=232027&r2=232028&view=diff
==============================================================================
--- cfe/branches/release_36/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/branches/release_36/include/clang/Basic/DiagnosticSemaKinds.td Thu Mar 12 06:14:45 2015
@@ -6972,6 +6972,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/branches/release_36/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_36/include/clang/Basic/TargetInfo.h?rev=232028&r1=232027&r2=232028&view=diff
==============================================================================
--- cfe/branches/release_36/include/clang/Basic/TargetInfo.h (original)
+++ cfe/branches/release_36/include/clang/Basic/TargetInfo.h Thu Mar 12 06:14:45 2015
@@ -852,6 +852,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/branches/release_36/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_36/include/clang/Sema/Sema.h?rev=232028&r1=232027&r2=232028&view=diff
==============================================================================
--- cfe/branches/release_36/include/clang/Sema/Sema.h (original)
+++ cfe/branches/release_36/include/clang/Sema/Sema.h Thu Mar 12 06:14:45 2015
@@ -8550,6 +8550,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/branches/release_36/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_36/lib/Basic/Targets.cpp?rev=232028&r1=232027&r2=232028&view=diff
==============================================================================
--- cfe/branches/release_36/lib/Basic/Targets.cpp (original)
+++ cfe/branches/release_36/lib/Basic/Targets.cpp Thu Mar 12 06:14:45 2015
@@ -919,6 +919,10 @@ public:
     if (RegNo == 1) return 4;
     return -1;
   }
+
+  bool hasSjLjLowering() const override {
+    return true;
+  }
 };
 
 const Builtin::Info PPCTargetInfo::BuiltinInfo[] = {
@@ -2181,6 +2185,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/branches/release_36/lib/CodeGen/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_36/lib/CodeGen/TargetInfo.cpp?rev=232028&r1=232027&r2=232028&view=diff
==============================================================================
--- cfe/branches/release_36/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/branches/release_36/lib/CodeGen/TargetInfo.cpp Thu Mar 12 06:14:45 2015
@@ -664,7 +664,6 @@ public:
                    ('T' << 24);
     return llvm::ConstantInt::get(CGM.Int32Ty, Sig);
   }
-
 };
 
 }
@@ -4455,7 +4454,6 @@ public:
                                               llvm::AttributeSet::FunctionIndex,
                                               B));
   }
-
 };
 
 }

Modified: cfe/branches/release_36/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_36/lib/Sema/SemaChecking.cpp?rev=232028&r1=232027&r2=232028&view=diff
==============================================================================
--- cfe/branches/release_36/lib/Sema/SemaChecking.cpp (original)
+++ cfe/branches/release_36/lib/Sema/SemaChecking.cpp Thu Mar 12 06:14:45 2015
@@ -297,6 +297,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;
@@ -2367,8 +2371,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;
 
@@ -2383,6 +2392,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/branches/release_36/test/CodeGen/2003-08-06-BuiltinSetjmpLongjmp.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_36/test/CodeGen/2003-08-06-BuiltinSetjmpLongjmp.c?rev=232027&view=auto
==============================================================================
--- cfe/branches/release_36/test/CodeGen/2003-08-06-BuiltinSetjmpLongjmp.c (original)
+++ cfe/branches/release_36/test/CodeGen/2003-08-06-BuiltinSetjmpLongjmp.c (removed)
@@ -1,15 +0,0 @@
-/* RUN: %clang_cc1  %s -emit-llvm -o - | FileCheck %s
- *
- * __builtin_longjmp/setjmp should get transformed into intrinsics.
- */
-
-// CHECK-NOT: builtin_longjmp
-
-void jumpaway(int *ptr) {
-  __builtin_longjmp(ptr,1);
-}
-    
-int main(void) {
-  __builtin_setjmp(0);
-  jumpaway(0);
-}

Modified: cfe/branches/release_36/test/CodeGen/builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_36/test/CodeGen/builtins.c?rev=232028&r1=232027&r2=232028&view=diff
==============================================================================
--- cfe/branches/release_36/test/CodeGen/builtins.c (original)
+++ cfe/branches/release_36/test/CodeGen/builtins.c Thu Mar 12 06:14:45 2015
@@ -220,6 +220,8 @@ void test_float_builtin_ops(float F, dou
   // CHECK: call x86_fp80 @llvm.fabs.f80(x86_fp80
 }
 
+// __builtin_longjmp isn't supported on all platforms, so only test it on X86.
+#ifdef __x86_64__
 // CHECK-LABEL: define void @test_builtin_longjmp
 void test_builtin_longjmp(void **buffer) {
   // CHECK: [[BITCAST:%.*]] = bitcast
@@ -227,6 +229,7 @@ void test_builtin_longjmp(void **buffer)
   __builtin_longjmp(buffer, 1);
   // CHECK-NEXT: unreachable
 }
+#endif
 
 // CHECK-LABEL: define i64 @test_builtin_readcyclecounter
 long long test_builtin_readcyclecounter() {





More information about the llvm-branch-commits mailing list