[cfe-commits] r165914 - in /cfe/trunk: lib/CodeGen/CodeGenFunction.cpp test/CodeGenCXX/return.cpp

Richard Smith richard-llvm at metafoo.co.uk
Sun Oct 14 17:23:07 PDT 2012


Author: rsmith
Date: Sun Oct 14 19:23:07 2012
New Revision: 165914

URL: http://llvm.org/viewvc/llvm-project?rev=165914&view=rev
Log:
At -O0, emit an @llvm.trap() call at the end of a value-returning function which
fails to return a value, to make debugging this issue easier.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/test/CodeGenCXX/return.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=165914&r1=165913&r2=165914&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Sun Oct 14 19:23:07 2012
@@ -547,6 +547,8 @@
       EmitCheck(Builder.getFalse(), "missing_return",
                 EmitCheckSourceLocation(FD->getLocation()),
                 llvm::ArrayRef<llvm::Value*>());
+    else if (CGM.getCodeGenOpts().OptimizationLevel == 0)
+      Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::trap));
     Builder.CreateUnreachable();
     Builder.ClearInsertionPoint();
   }

Modified: cfe/trunk/test/CodeGenCXX/return.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/return.cpp?rev=165914&r1=165913&r2=165914&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/return.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/return.cpp Sun Oct 14 19:23:07 2012
@@ -1,6 +1,12 @@
-// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O0 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O -o - %s | FileCheck %s --check-prefix=CHECK-OPT
 
-// CHECK: @_Z9no_return
+// CHECK:     @_Z9no_return
+// CHECK-OPT: @_Z9no_return
 int no_return() {
-  // CHECK: unreachable
+  // CHECK:      call void @llvm.trap
+  // CHECK-NEXT: unreachable
+
+  // CHECK-OPT-NOT: call void @llvm.trap
+  // CHECK-OPT:     unreachable
 }





More information about the cfe-commits mailing list