From 260c6b8b5a0706151e304a53c347cbd2c8c68fe1 Mon Sep 17 00:00:00 2001
From: Maximilian Downey Twiss <creatorsmithmdt@gmail.com>
Date: Thu, 17 Nov 2022 13:56:46 +1100
Subject: [PATCH 06/56] Re-add tests for Java.

gcc/testsuite/ChangeLog:

	* g++.dg/ext/java-1.C: Re-add test.
	* g++.dg/ext/java-2.C: Likewise.
	* g++.dg/ext/java-3.C: Likewise.
	* g++.dg/ext/pr34829.C: Likewise.
	* g++.dg/lookup/java1.C: Likewise.
	* g++.dg/lookup/java2.C: Likewise.
	* g++.dg/other/error12.C: Likewise.
	* g++.dg/other/java1.C: Likewise.
	* g++.dg/other/java2.C: Likewise.
	* g++.dg/other/java3.C: Likewise.
	* g++.dg/warn/Wnvdtor.C: Likewise.
	* g++.old-deja/g++.oliva/dwarf2.C: Likewise.
---
 gcc/testsuite/g++.dg/ext/java-1.C             | 26 ++++++
 gcc/testsuite/g++.dg/ext/java-2.C             | 79 +++++++++++++++++++
 gcc/testsuite/g++.dg/ext/java-3.C             | 39 +++++++++
 gcc/testsuite/g++.dg/ext/pr34829.C            | 22 ++++++
 gcc/testsuite/g++.dg/lookup/java1.C           | 68 ++++++++++++++++
 gcc/testsuite/g++.dg/lookup/java2.C           | 47 +++++++++++
 gcc/testsuite/g++.dg/other/error12.C          |  9 +++
 gcc/testsuite/g++.dg/other/java1.C            | 22 ++++++
 gcc/testsuite/g++.dg/other/java2.C            | 11 +++
 gcc/testsuite/g++.dg/other/java3.C            |  7 ++
 gcc/testsuite/g++.dg/warn/Wnvdtor.C           | 11 +++
 gcc/testsuite/g++.old-deja/g++.oliva/dwarf2.C | 10 +++
 12 files changed, 351 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/ext/java-1.C
 create mode 100644 gcc/testsuite/g++.dg/ext/java-2.C
 create mode 100644 gcc/testsuite/g++.dg/ext/java-3.C
 create mode 100644 gcc/testsuite/g++.dg/ext/pr34829.C
 create mode 100644 gcc/testsuite/g++.dg/lookup/java1.C
 create mode 100644 gcc/testsuite/g++.dg/lookup/java2.C
 create mode 100644 gcc/testsuite/g++.dg/other/error12.C
 create mode 100644 gcc/testsuite/g++.dg/other/java1.C
 create mode 100644 gcc/testsuite/g++.dg/other/java2.C
 create mode 100644 gcc/testsuite/g++.dg/other/java3.C
 create mode 100644 gcc/testsuite/g++.dg/warn/Wnvdtor.C
 create mode 100644 gcc/testsuite/g++.old-deja/g++.oliva/dwarf2.C

diff --git a/gcc/testsuite/g++.dg/ext/java-1.C b/gcc/testsuite/g++.dg/ext/java-1.C
new file mode 100644
index 00000000000..f88e1fcab5d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/java-1.C
@@ -0,0 +1,26 @@
+// { dg-do compile { target { ! { powerpc-ibm-aix* } } } }
+// { dg-options "" }
+// Test extern "java" and some throwing of the objects.
+
+extern "Java"
+  namespace java
+  {
+    namespace lang
+    {
+      class Throwable;
+      class Class;
+  }
+}
+typedef class java::lang::Throwable* jthrowable;
+typedef class java::lang::Class* jclass;
+class java::lang::Throwable {
+public:
+  static jclass class$;
+};
+int
+_Jv_FindClassFromSignature ( )
+  try 
+    {
+    }
+  catch (java::lang::Throwable *ncdfe) {} 
+
diff --git a/gcc/testsuite/g++.dg/ext/java-2.C b/gcc/testsuite/g++.dg/ext/java-2.C
new file mode 100644
index 00000000000..8114517b942
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/java-2.C
@@ -0,0 +1,79 @@
+// PR c++/30293
+// PR c++/30294
+// { dg-do compile { target { ! { powerpc-ibm-aix* } } } }
+// { dg-options "" }
+
+extern "Java" {
+typedef __java_byte jbyte;
+namespace java {
+namespace lang {
+  class Object {};
+  class Class {};
+}
+}
+typedef struct java::lang::Object* jobject;
+typedef java::lang::Class *jclass;
+}
+extern "C" jobject _Jv_AllocObject (jclass);
+
+extern "Java" {
+  struct A { static java::lang::Class class$; };
+}
+
+struct B {
+  A a;		// { dg-error "has Java class type" }
+};
+
+void* operator new (__SIZE_TYPE__, void*) throw();
+char buf[1024];
+
+A a;		// { dg-error "not allocated with" }
+A b = A ();	// { dg-error "not allocated with" }
+A *c = new ((void *) buf) A ();	// { dg-error "using placement new" }
+A *d = new A ();
+jbyte e = 6;
+
+const A fn1 ()	// { dg-error "return type has Java class type" }
+{
+  A a;		// { dg-error "not allocated with" }
+  return a;
+}
+
+A fn2 ()	// { dg-error "return type has Java class type" }
+{
+  A a;		// { dg-error "not allocated with" }
+  return a;
+}
+
+A *fn3 ()
+{
+  return new A ();
+}
+
+A &fn4 ()
+{
+  return *c;
+}
+
+jbyte fn5 ()
+{
+  return 7;
+}
+
+void fn6 (A x)	// { dg-error "has Java class type" }
+{
+}
+
+void fn7 (const A x)	// { dg-error "has Java class type" }
+{
+}
+
+void fn8 (A *x)
+{
+  (void) x;
+}
+
+void fn9 (jbyte x)
+{
+  (void) x;
+}
diff --git a/gcc/testsuite/g++.dg/ext/java-3.C b/gcc/testsuite/g++.dg/ext/java-3.C
new file mode 100644
index 00000000000..128db653116
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/java-3.C
@@ -0,0 +1,39 @@
+// PR c++/70267
+// { dg-do compile { target { ! { powerpc-ibm-aix* } } } }
+// { dg-options "-O2" }
+
+extern "Java"
+{
+  typedef __java_int jint;
+  namespace java
+  {
+    namespace lang
+    {
+      class Class;
+      class Object;
+      class Throwable {};
+      class Foo;
+    }
+  }
+} 
+
+typedef struct java::lang::Object * jobject;
+typedef struct java::lang::Throwable * jthrowable;
+typedef class  java::lang::Class * jclass;
+
+using java::lang::Foo;
+
+class Foo: public java::lang::Throwable
+{
+  public:static::java::lang::Class class$;
+};
+
+extern "C" Foo _Jv_AllocObject (jclass);
+extern "C" void _Jv_Throw (jthrowable) __attribute__ ((__noreturn__));
+
+void 
+Bar4 (void)
+{
+  Foo * f = new java::lang::Foo;	// { dg-error "is not a function returning a pointer" }
+  throw (f);
+}
diff --git a/gcc/testsuite/g++.dg/ext/pr34829.C b/gcc/testsuite/g++.dg/ext/pr34829.C
new file mode 100644
index 00000000000..d588b5b2bbd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/pr34829.C
@@ -0,0 +1,22 @@
+// Test for PR c++/34829
+// Placement new should be ok for non-aggregate Java types.
+
+// { dg-do compile }
+// { dg-options "" }
+
+extern "Java"
+{
+  typedef __java_byte jbyte;
+}
+
+typedef __SIZE_TYPE__ size_t;
+
+void *operator new (size_t, void *m)
+{
+  return m;
+}
+
+jbyte *f(void *memory)
+{
+  return new (memory) jbyte;
+}
diff --git a/gcc/testsuite/g++.dg/lookup/java1.C b/gcc/testsuite/g++.dg/lookup/java1.C
new file mode 100644
index 00000000000..0d9b22ee1d5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lookup/java1.C
@@ -0,0 +1,68 @@
+// { dg-do compile }
+// { dg-options "-fdollars-in-identifiers" }
+// Origin: Giovanni Bajo <giovannibajo at libero dot it>
+// Make sure that Java special functions can be called correctly.
+
+extern "Java"
+{
+  typedef __java_int jint;
+  namespace java
+  {
+    namespace lang
+    {
+      class Class;
+      class Object;
+      class Throwable {};
+      class Foo;
+    }
+  }
+}
+
+typedef struct java::lang::Object* jobject;
+typedef struct java::lang::Throwable* jthrowable;
+typedef class java::lang::Class* jclass;
+using java::lang::Foo;
+
+class Foo : public java::lang::Throwable
+{
+public:
+  static ::java::lang::Class class$;
+};
+
+
+/*
+ * Step 1: no declarations. A declaration for _Jv_Throw is created.
+ */
+
+void Bar1(void)
+{
+  Foo* f = new java::lang::Foo;   // { dg-error "call to Java constructor" }
+  throw (f);
+}
+
+
+/*
+ * Step 2: constructor declaration
+ */
+
+extern "C" jobject _Jv_AllocObject (jclass) __attribute__((__malloc__));
+
+void Bar2(void)
+{
+  Foo* f = new java::lang::Foo; 
+  throw (f);  
+}
+
+
+/*
+ * Step 3: overloads
+ */
+
+jobject _Jv_AllocObject (jclass, jint, float) __attribute__((__malloc__));
+void _Jv_Throw (int, float) __attribute__ ((__noreturn__));
+
+void Bar3(void)
+{
+  Foo* f = new java::lang::Foo;	  // { dg-error "should never be overloaded" }
+  throw (f);			  // { dg-error "should never be overloaded" }
+}
diff --git a/gcc/testsuite/g++.dg/lookup/java2.C b/gcc/testsuite/g++.dg/lookup/java2.C
new file mode 100644
index 00000000000..26fd36922b6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lookup/java2.C
@@ -0,0 +1,47 @@
+// { dg-do compile }
+// { dg-options "-fdollars-in-identifiers" }
+// Origin: Giovanni Bajo <giovannibajo at libero dot it>
+// Make sure that Java special functions can be called correctly.
+// (continue from java1.C)
+
+extern "Java"
+{
+  typedef __java_int jint;
+  namespace java
+  {
+    namespace lang
+    {
+      class Class;
+      class Object;
+      class Throwable {};
+      class Foo;
+    }
+  }
+}
+
+typedef struct java::lang::Object* jobject;
+typedef struct java::lang::Throwable* jthrowable;
+typedef class java::lang::Class* jclass;
+using java::lang::Foo;
+
+class Foo : public java::lang::Throwable
+{
+public:
+  static ::java::lang::Class class$;
+};
+
+/*
+ * Step 4: Manual declaration of _Jv_Throw
+ *  This is the last case we need to test. In the other file we're testing
+ *  the compiler is able to generate an artifical declaration for this 
+ *  function, so we need to test here if it works with a normal declaration.
+ */
+
+extern "C" jobject _Jv_AllocObject (jclass) __attribute__((__malloc__));
+extern "C" void _Jv_Throw (jthrowable) __attribute__ ((__noreturn__));
+
+void Bar4(void)
+{
+  Foo* f = new java::lang::Foo;
+  throw (f);
+}
diff --git a/gcc/testsuite/g++.dg/other/error12.C b/gcc/testsuite/g++.dg/other/error12.C
new file mode 100644
index 00000000000..253561e8feb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/error12.C
@@ -0,0 +1,9 @@
+//PR c++/28292
+
+extern "Java"
+{
+  struct A
+  {
+    void foo(void; // { dg-error "before|incomplete type|invalid use" }
+  };
+}
diff --git a/gcc/testsuite/g++.dg/other/java1.C b/gcc/testsuite/g++.dg/other/java1.C
new file mode 100644
index 00000000000..38b5e0c3070
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/java1.C
@@ -0,0 +1,22 @@
+// { dg-options "-w -ansi -pedantic" }
+
+// Copyright (C) 2003 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 23 Oct 2003 <nathan@codesourcery.com>
+
+extern "Java" {
+  class One 
+  {
+    ~One (); // { dg-error "cannot have a destructor" "" }
+    One ();
+  };
+
+  class Two {};
+
+  class Three : One {}; // { dg-error "cannot have an implicit" "" }
+
+  class Four : Two {};
+
+  class Five : Two, Four {}; //  { dg-error "cannot have multiple bases" "" }
+
+  class Six : virtual Two {}; // { dg-error "cannot have virtual base" "" }
+}
diff --git a/gcc/testsuite/g++.dg/other/java2.C b/gcc/testsuite/g++.dg/other/java2.C
new file mode 100644
index 00000000000..8ba4d5a72c8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/java2.C
@@ -0,0 +1,11 @@
+// PR c++/???
+// { dg-do compile }
+
+extern "Java"
+{
+  struct A {};
+}
+
+typedef void* jclass;
+
+A* p = new A;  // { dg-error "class\\$" }
diff --git a/gcc/testsuite/g++.dg/other/java3.C b/gcc/testsuite/g++.dg/other/java3.C
new file mode 100644
index 00000000000..1bc0a8874fe
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/java3.C
@@ -0,0 +1,7 @@
+// PR c++/11006
+
+typedef int* jclass;
+
+void foo () {
+  new __java_boolean;  // { dg-error "valid" }
+}
diff --git a/gcc/testsuite/g++.dg/warn/Wnvdtor.C b/gcc/testsuite/g++.dg/warn/Wnvdtor.C
new file mode 100644
index 00000000000..f03cff5b31c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wnvdtor.C
@@ -0,0 +1,11 @@
+// { dg-options "-Wnon-virtual-dtor" }
+
+extern "Java"
+{
+  class Foo
+  {
+  public:
+    virtual void bar( void);
+  };
+}
+
diff --git a/gcc/testsuite/g++.old-deja/g++.oliva/dwarf2.C b/gcc/testsuite/g++.old-deja/g++.oliva/dwarf2.C
new file mode 100644
index 00000000000..c50b1b7d6be
--- /dev/null
+++ b/gcc/testsuite/g++.old-deja/g++.oliva/dwarf2.C
@@ -0,0 +1,10 @@
+// { dg-do assemble }
+
+// Copyright (C) 1999 Free Software Foundation
+
+// by Alexandre Oliva <oliva@dcc.unicamp.br>
+
+// Fails with dwarf debugging.
+
+typedef __java_boolean jboolean;
+void foo() {}
-- 
2.38.1

