summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/opt/pr19650.C
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/g++.dg/opt/pr19650.C
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/g++.dg/opt/pr19650.C')
-rw-r--r--gcc/testsuite/g++.dg/opt/pr19650.C71
1 files changed, 71 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/opt/pr19650.C b/gcc/testsuite/g++.dg/opt/pr19650.C
new file mode 100644
index 000000000..1f495cb7d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr19650.C
@@ -0,0 +1,71 @@
+// { dg-options "-O1 -w -fpermissive" }
+// { dg-do run }
+// Tests the fold bug described in PR 19650.
+#include <stdio.h>
+#include <stdlib.h>
+#define test(a) ((a) ? 1 : 0)
+
+typedef int (*arg_cmp_func)();
+
+class Item_func
+{
+public:
+ enum Functype { UNKNOWN_FUNC, EQ_FUNC, EQUAL_FUNC };
+ virtual enum Functype functype() const { return UNKNOWN_FUNC; }
+};
+
+class Item_bool_func2 : public Item_func
+{
+public:
+ virtual enum Functype functype() const { return EQUAL_FUNC; }
+};
+
+class Arg_comparator
+{
+public:
+ Item_bool_func2 *owner;
+ arg_cmp_func func;
+ static arg_cmp_func comparator_matrix[4][2];
+
+ int Arg_comparator::set_compare_func(Item_bool_func2 *item, int type)
+ {
+ owner = item;
+
+ /****************** problematic line is here ************************/
+
+ func = comparator_matrix[type][test(owner->functype() == Item_func::EQUAL_FUNC)];
+ return 0;
+ }
+};
+
+int compare_string() { return 0; }
+int compare_e_string() { return 0; }
+int compare_real() { return 0; }
+int compare_e_real() { return 0; }
+int compare_int_signed() { return 0; }
+int compare_e_int() { return 0; }
+int compare_row() { return 0; }
+int compare_e_row() { return 0; }
+
+arg_cmp_func Arg_comparator::comparator_matrix[4][2] =
+ {{&compare_string, &compare_e_string},
+ {&compare_real, &compare_e_real},
+ {&compare_int_signed, &compare_e_int},
+ {&compare_row, &compare_e_row}};
+
+void myfunc (const char*p, arg_cmp_func f1, arg_cmp_func f2) __attribute__((noinline));
+void myfunc (const char*p, arg_cmp_func f1, arg_cmp_func f2)
+{
+ if (f1!=f2)
+ abort ();
+}
+
+int main()
+{
+ Arg_comparator cmp;
+ Item_bool_func2 equal_func;
+
+ cmp.set_compare_func(&equal_func, 0);
+ myfunc("cmp.func is %p (expected %p)\n", cmp.func, &compare_e_string);
+}
+