aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorHans-Peter Nilsson <hp@axis.com>2024-01-22 01:09:03 +0100
committerHans-Peter Nilsson <hp@bitrange.com>2024-02-10 04:41:18 +0100
commit48207a5f00d6ae7cb11038e7c17f6858de4a884e (patch)
tree6511d2d7345714739a7651252c6c402ecf6d82a1 /gcc
parent863202684dff775ae4a3e576f77044474384d41f (diff)
downloadgcc-48207a5f00d6ae7cb11038e7c17f6858de4a884e.zip
gcc-48207a5f00d6ae7cb11038e7c17f6858de4a884e.tar.gz
gcc-48207a5f00d6ae7cb11038e7c17f6858de4a884e.tar.bz2
c++: testcases for PR113545 (constexpr with switch and passing non-constexpr parameter)
Test-cases, with constexpr-reinterpret3.C dg-ice:ing the PR c++/113545 bug. Regarding the request in the comment, A dg-do run when there's an ICE will cause some CI's to signal an error for the run being "UNRESOLVED" (compilation failed to produce executable). Note that dejagnu (1.6.3) itself doesn't consider this an error. gcc/testsuite: PR c++/113545 * g++.dg/cpp1y/constexpr-reinterpret3.C, g++.dg/cpp1y/constexpr-reinterpret4.C: New tests.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/constexpr-reinterpret3.C56
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/constexpr-reinterpret4.C54
2 files changed, 110 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-reinterpret3.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-reinterpret3.C
new file mode 100644
index 0000000..51feb2e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-reinterpret3.C
@@ -0,0 +1,56 @@
+// PR c++/113545
+// { dg-do compile { target c++14 } }
+// Please change the above "dg-do compile" to "dg-do run" when the ICE is resolved.
+// { dg-ice "PR112545 - constexpr function with switch called for reinterpret_cast" }
+
+char foo;
+
+// This one caught a call to gcc_unreachable in
+// cp/constexpr.cc:label_matches, when passed a convert_expr from the
+// cast in the call.
+constexpr unsigned char swbar(__UINTPTR_TYPE__ baz)
+{
+ switch (baz)
+ {
+ case 13:
+ return 11;
+ case 14:
+ return 78;
+ case 2048:
+ return 13;
+ default:
+ return 42;
+ }
+}
+
+// For reference, the equivalent* if-statements.
+constexpr unsigned char ifbar(__UINTPTR_TYPE__ baz)
+{
+ if (baz == 13)
+ return 11;
+ else if (baz == 14)
+ return 78;
+ else if (baz == 2048)
+ return 13;
+ else
+ return 42;
+}
+
+__attribute__ ((__noipa__))
+void xyzzy(int x)
+{
+ if (x != 42)
+ __builtin_abort ();
+}
+
+int main()
+{
+ unsigned const char c = swbar(reinterpret_cast<__UINTPTR_TYPE__>(&foo));
+ xyzzy(c);
+ unsigned const char d = ifbar(reinterpret_cast<__UINTPTR_TYPE__>(&foo));
+ xyzzy(d);
+ unsigned const char e = swbar((__UINTPTR_TYPE__) &foo);
+ xyzzy(e);
+ unsigned const char f = ifbar((__UINTPTR_TYPE__) &foo);
+ xyzzy(f);
+}
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-reinterpret4.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-reinterpret4.C
new file mode 100644
index 0000000..9aaa6e4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-reinterpret4.C
@@ -0,0 +1,54 @@
+// PR c++/113545
+// { dg-do compile { target c++14 } }
+
+char foo;
+
+// This one caught a call to gcc_unreachable in
+// cp/constexpr.cc:label_matches, when passed a convert_expr from the
+// cast in the call.
+constexpr unsigned char swbar(__UINTPTR_TYPE__ baz)
+{
+ switch (baz)
+ {
+ case 13:
+ return 11;
+ case 14:
+ return 78;
+ case 2048:
+ return 13;
+ default:
+ return 42;
+ }
+}
+
+// For reference, the equivalent* if-statements.
+constexpr unsigned char ifbar(__UINTPTR_TYPE__ baz)
+{
+ if (baz == 13)
+ return 11;
+ else if (baz == 14)
+ return 78;
+ else if (baz == 2048)
+ return 13;
+ else
+ return 42;
+}
+
+__attribute__ ((__noipa__))
+void xyzzy(int x)
+{
+ if (x != 42)
+ __builtin_abort ();
+}
+
+int main()
+{
+ unsigned constexpr char c = swbar(reinterpret_cast<__UINTPTR_TYPE__>(&foo)); // { dg-error "conversion from pointer type" }
+ xyzzy(c);
+ unsigned constexpr char d = ifbar(reinterpret_cast<__UINTPTR_TYPE__>(&foo)); // { dg-error "conversion from pointer type" }
+ xyzzy(d);
+ unsigned constexpr char e = swbar((__UINTPTR_TYPE__) &foo); // { dg-error "conversion from pointer type" }
+ xyzzy(e);
+ unsigned constexpr char f = ifbar((__UINTPTR_TYPE__) &foo); // { dg-error "conversion from pointer type" }
+ xyzzy(f);
+}