I've changed the test so that it calls __cxa_throw_bad_array_new_length()
(I'm mad at whoever gave this function such a long name) directly rather
than expecting the compiler to call it for bad input to new[]. That check
can go in the compiler tests.

On Thu, Sep 11, 2014 at 6:39 AM, Aaron Ballman <[email protected]>
wrote:

> On Wed, Sep 10, 2014 at 11:52 AM, Dan Albert <[email protected]> wrote:
> > Sorry, I got used to relying on phabricator to keep track of things, and
> > forgot about this one.
>
> No worries!
>
> > Could you split the test in to a separate file and add `// XFAIL: *` at
> the
> > top? That way you can commit it with the guts of the patch and we don't
> have
> > to worry about forgetting to submit the test later.
> >
> > Other than that, LGTM.
>
> I've split the test out into its own file, and have attached the patch
> here.
>
> Since I don't have a way to test this locally, and no other tests have
> XFAIL lines, I'm not quite comfortable committing this without someone
> who can run the tests confirming that it runs cleanly.
>
> Thanks!
>
> ~Aaron
>
From c942105b0866827666454a823cfe494aacc15a4c Mon Sep 17 00:00:00 2001
From: Aaron Ballman <[email protected]>
Date: Thu, 11 Sep 2014 10:03:16 -0700
Subject: [PATCH] Add support of __cxa_throw_bad_array_new_length().

The compilers don't support this yet (since we weren't able to service
the calls), so test the function directly rather than checking `new
int[BAD_LENGTH]`. That test belongs in the compiler.

Signed-off-by: Dan Albert <[email protected]>
---
 CREDITS.TXT                       |  4 ++++
 include/cxxabi.h                  |  1 +
 src/cxa_aux_runtime.cpp           |  5 +++++
 test/cxa_bad_array_new_length.cpp | 39 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 49 insertions(+)
 create mode 100644 test/cxa_bad_array_new_length.cpp

diff --git a/CREDITS.TXT b/CREDITS.TXT
index 6e491c5..9c910fc 100644
--- a/CREDITS.TXT
+++ b/CREDITS.TXT
@@ -8,6 +8,10 @@ beautification by scripts.  The fields are: name (N), email (E), web-address
 (W), PGP key ID and fingerprint (P), description (D), and snail-mail address
 (S).
 
+N: Aaron Ballman
+E: [email protected]
+D: Minor patches
+
 N: Logan Chien
 E: [email protected]
 D: ARM EHABI Unwind & Exception Handling
diff --git a/include/cxxabi.h b/include/cxxabi.h
index 867ba72..46d6730 100644
--- a/include/cxxabi.h
+++ b/include/cxxabi.h
@@ -66,6 +66,7 @@ extern LIBCXXABI_NORETURN void __cxa_rethrow();
 // 2.6 Auxiliary Runtime APIs
 extern LIBCXXABI_NORETURN void __cxa_bad_cast(void);
 extern LIBCXXABI_NORETURN void __cxa_bad_typeid(void);
+extern LIBCXXABI_NORETURN void __cxa_throw_bad_array_new_length(void);
 
 
 
diff --git a/src/cxa_aux_runtime.cpp b/src/cxa_aux_runtime.cpp
index 15fede0..7fec810 100644
--- a/src/cxa_aux_runtime.cpp
+++ b/src/cxa_aux_runtime.cpp
@@ -11,6 +11,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "cxxabi.h"
+#include <new>
 #include <typeinfo>
 
 namespace __cxxabiv1
@@ -29,6 +30,10 @@ void __cxa_bad_typeid(void) {
     throw std::bad_typeid();
 }
 
+LIBCXXABI_NORETURN
+void __cxa_throw_bad_array_new_length(void) {
+    throw std::bad_array_new_length();
+}
 }  // extern "C"
 
 }  // abi
diff --git a/test/cxa_bad_array_new_length.cpp b/test/cxa_bad_array_new_length.cpp
new file mode 100644
index 0000000..9f37db0
--- /dev/null
+++ b/test/cxa_bad_array_new_length.cpp
@@ -0,0 +1,39 @@
+// This test currently fails because Clang does not currently codegen the
+// correct call to __cxa_bad_array_new_length, so this test would result in
+// passing -1 to ::operator new[], which would then throw a std::bad_alloc,
+// causing the test to fail.
+
+//===-------------------------- test_aux_runtime_op_array_new.cpp ---------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <iostream>
+#include <cxxabi.h>
+
+//  If the expression passed to operator new[] would result in an overflow, the
+//  allocation function is not called, and a std::bad_array_new_length exception
+//  is thrown instead (5.3.4p7).
+bool bad_array_new_length_test() {
+    try {
+      __cxxabiv1::__cxa_throw_bad_array_new_length();
+    } catch (const std::bad_array_new_length &banl) {
+      return true;
+    }
+    return false;
+}
+
+int main(int argc, char *argv[]) {
+    int ret_val = 0;
+
+    if (!bad_array_new_length_test()) {
+        std::cerr << "Bad array new length test failed!" << std::endl;
+        ret_val = 1;
+    }
+
+    return ret_val;
+}
-- 
2.1.0.rc2.206.gedb03e5

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to