summaryrefslogtreecommitdiffstats
path: root/llvm/test
diff options
context:
space:
mode:
authorKevin Enderby <enderby@apple.com>2015-10-21 16:59:24 +0000
committerKevin Enderby <enderby@apple.com>2015-10-21 16:59:24 +0000
commite3bf4fd546eea6743ab2944427bcb872a8cece0a (patch)
tree701226dd2cfd459c223573356ba132d155d383e8 /llvm/test
parent998039e2f606cb90841acee47f828b7163309ece (diff)
downloadbcm5719-llvm-e3bf4fd546eea6743ab2944427bcb872a8cece0a.tar.gz
bcm5719-llvm-e3bf4fd546eea6743ab2944427bcb872a8cece0a.zip
This removes the eating of the error in Archive::Child::getSize() when the characters
in the size field in the archive header for the member is not a number. To do this we have all of the needed methods return ErrorOr to push them up until we get out of lib. Then the tools and can handle the error in whatever way is appropriate for that tool. So the solution is to plumb all the ErrorOr stuff through everything that touches archives. This include its iterators as one can create an Archive object but the first or any other Child object may fail to be created due to a bad size field in its header. Thanks to Lang Hames on the changes making child_iterator contain an ErrorOr<Child> instead of a Child and the needed changes to ErrorOr.h to add operator overloading for * and -> . We don’t want to use llvm_unreachable() as it calls abort() and is produces a “crash” and using report_fatal_error() to move the error checking will cause the program to stop, neither of which are really correct in library code. There are still some uses of these that should be cleaned up in this library code for other than the size field. Also corrected the code where the size gets us to the “at the end of the archive” which is OK but past the end of the archive will return object_error::parse_failed now. The test cases use archives with text files so one can see the non-digit character, in this case a ‘%’, in the size field. llvm-svn: 250906
Diffstat (limited to 'llvm/test')
-rw-r--r--llvm/test/tools/llvm-objdump/Inputs/malformed-archives/libbogus1.a13
-rw-r--r--llvm/test/tools/llvm-objdump/Inputs/malformed-archives/libbogus2.a13
-rw-r--r--llvm/test/tools/llvm-objdump/Inputs/malformed-archives/libbogus3.a16
-rw-r--r--llvm/test/tools/llvm-objdump/malformed-archives.test20
4 files changed, 62 insertions, 0 deletions
diff --git a/llvm/test/tools/llvm-objdump/Inputs/malformed-archives/libbogus1.a b/llvm/test/tools/llvm-objdump/Inputs/malformed-archives/libbogus1.a
new file mode 100644
index 00000000000..510c1455527
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/Inputs/malformed-archives/libbogus1.a
@@ -0,0 +1,13 @@
+!<arch>
+hello.c 1444941273 124 0 100644 10% `
+#include <stdio.h>
+#include <stdlib.h>
+int
+main()
+{
+ printf("Hello World\n");
+ return EXIT_SUCCESS;
+}
+foo.c 1444941645 124 0 100644 1% `
+void foo(void){}
+
diff --git a/llvm/test/tools/llvm-objdump/Inputs/malformed-archives/libbogus2.a b/llvm/test/tools/llvm-objdump/Inputs/malformed-archives/libbogus2.a
new file mode 100644
index 00000000000..2ccb7f31c09
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/Inputs/malformed-archives/libbogus2.a
@@ -0,0 +1,13 @@
+!<arch>
+hello.c 1444941273 124 0 100644 102 `
+#include <stdio.h>
+#include <stdlib.h>
+int
+main()
+{
+ printf("Hello World\n");
+ return EXIT_SUCCESS;
+}
+foo.c 1444941645 124 0 100644 1% `
+void foo(void){}
+
diff --git a/llvm/test/tools/llvm-objdump/Inputs/malformed-archives/libbogus3.a b/llvm/test/tools/llvm-objdump/Inputs/malformed-archives/libbogus3.a
new file mode 100644
index 00000000000..f15a7329f9f
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/Inputs/malformed-archives/libbogus3.a
@@ -0,0 +1,16 @@
+!<arch>
+hello.c 1444941273 124 0 100644 102 `
+#include <stdio.h>
+#include <stdlib.h>
+int
+main()
+{
+ printf("Hello World\n");
+ return EXIT_SUCCESS;
+}
+foo.c 1444941645 124 0 100644 171 `
+void foo(void){}
+
+bar.c 1445026190 124 0 100644 17 `
+void foo(void){}
+
diff --git a/llvm/test/tools/llvm-objdump/malformed-archives.test b/llvm/test/tools/llvm-objdump/malformed-archives.test
new file mode 100644
index 00000000000..5066cb543b4
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/malformed-archives.test
@@ -0,0 +1,20 @@
+// These test checks that llvm-objdump will not crash with malformed Archive
+// files. So the check line is not all that important but the bug fixes to
+// make sure llvm-objdump is robust is what matters.
+# RUN: llvm-objdump -macho -archive-headers \
+# RUN: %p/Inputs/malformed-archives/libbogus1.a \
+# RUN: 2>&1 | FileCheck -check-prefix=bogus1 %s
+
+# bogus1: Invalid data was encountered while parsing the file
+
+# RUN: llvm-objdump -macho -archive-headers \
+# RUN: %p/Inputs/malformed-archives/libbogus2.a \
+# RUN: 2>&1 | FileCheck -check-prefix=bogus2 %s
+
+# bogus2: hello.c
+
+# RUN: llvm-objdump -macho -archive-headers \
+# RUN: %p/Inputs/malformed-archives/libbogus3.a \
+# RUN: 2>&1 | FileCheck -check-prefix=bogus3 %s
+
+# bogus3: foo.c
OpenPOWER on IntegriCloud