Make sure the functions' range is empty before going through it in the LLVM C API...
authorAmaury Sechet <deadalnix@gmail.com>
Tue, 16 Feb 2016 08:37:01 +0000 (08:37 +0000)
committerAmaury Sechet <deadalnix@gmail.com>
Tue, 16 Feb 2016 08:37:01 +0000 (08:37 +0000)
llvm-svn: 260947

llvm/test/Bindings/llvm-c/empty.ll [new file with mode: 0644]
llvm/tools/llvm-c-test/echo.cpp

diff --git a/llvm/test/Bindings/llvm-c/empty.ll b/llvm/test/Bindings/llvm-c/empty.ll
new file mode 100644 (file)
index 0000000..eb73b83
--- /dev/null
@@ -0,0 +1,3 @@
+; RUN: llvm-as < %s | llvm-dis > %t.orig
+; RUN: llvm-as < %s | llvm-c-test --echo > %t.echo
+; RUN: diff -w %t.orig %t.echo
index d13a514..8ff75fb 100644 (file)
@@ -610,6 +610,11 @@ static void declare_function(LLVMValueRef Src, LLVMModuleRef M) {
 static void clone_functions(LLVMModuleRef Src, LLVMModuleRef Dst) {
   LLVMValueRef Begin = LLVMGetFirstFunction(Src);
   LLVMValueRef End = LLVMGetLastFunction(Src);
+  if (!Begin) {
+    if (End != nullptr)
+      report_fatal_error("Range has an end but no start");
+    return;
+  }
 
   // First pass, we declare all function
   LLVMValueRef Cur = Begin;