summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErick Ochoa <erick.ochoa@theobroma-systems.com>2020-05-13 10:02:40 +0200
committerErick Ochoa <erick.ochoa@theobroma-systems.com>2020-06-03 16:05:56 +0200
commit97d87476bf7a9d93583670da2618bfbb1440cc1b (patch)
tree826dc9f218d2be58847c6521eb3a65c59b5147ae
parent6ae1318387607c4ca05cae3ea84e54a3e86d8701 (diff)
Proof for incomplete type structural inequality
-rwxr-xr-xbuild.sh2
-rw-r--r--gcc/collect-types.c20
-rw-r--r--gcc/ipa-hello-world.c12
-rw-r--r--gcc/name-types.c2
-rw-r--r--gcc/passes.def2
-rw-r--r--gcc/testsuite/gcc.dg/ipa/type-playground-00.c6
-rw-r--r--gcc/testsuite/gcc.dg/ipa/type-playground-01.c19
-rw-r--r--gcc/types-inlines.h26
-rwxr-xr-xtest.sh3
9 files changed, 67 insertions, 25 deletions
diff --git a/build.sh b/build.sh
index 711b8c4bd56..ab3ed67cc9c 100755
--- a/build.sh
+++ b/build.sh
@@ -10,6 +10,6 @@ pushd $HOME/code/gcc-build/
$OLDPWD/configure --disable-bootstrap --disable-libsanitizer --enable-__cxa_atexit --enable-shared --disable-libsanitizer --enable-languages=c,c++,fortran --enable-lto --enable-gold --enable-linker-build-id --with-cpu-emag --prefix="$HOME/code/${installdir}/"
make -j `nproc`
make install -j `nproc`
-make check-gcc RUNTESTFLAGS="ipa.exp"
+${OLDPWD}/test.sh
popd
diff --git a/gcc/collect-types.c b/gcc/collect-types.c
index 3f04e0f8d45..01c019a2be8 100644
--- a/gcc/collect-types.c
+++ b/gcc/collect-types.c
@@ -77,25 +77,26 @@ collect_types_from_record_or_union_type(const_tree type, typeset &types)
const bool is_record = RECORD_TYPE == code;
const bool is_valid_input = is_union || is_record;
gcc_assert(is_valid_input);
+ assert_is_complete(type);
for (tree field = TYPE_FIELDS(type) ; field ; field = DECL_CHAIN(field))
{
const_tree field_type = TREE_TYPE(field);
- collect_types(field, types);
+ collect_types(field_type, types);
}
}
static void
collect_types_from_record_type(const_tree type, typeset &types)
{
- assert_is_type(type, RECORD_TYPE);
+ assert_is_complete_type(type, RECORD_TYPE);
collect_types_from_record_or_union_type(type, types);
}
static void
collect_types_from_union_type(const_tree type, typeset &types)
{
- assert_is_type(type, UNION_TYPE);
+ assert_is_complete_type(type, UNION_TYPE);
collect_types_from_record_or_union_type(type, types);
}
@@ -103,6 +104,7 @@ static void
collect_types_from_wrapper_type(const_tree type, typeset &types)
{
gcc_assert(type);
+ assert_is_complete(type);
const_tree inner_type = TREE_TYPE(type);
gcc_assert(inner_type);
collect_types(inner_type, types);
@@ -112,20 +114,21 @@ static void
collect_types_from_pointer_type(const_tree type, typeset &types)
{
assert_is_type(type, POINTER_TYPE);
+ assert_is_complete(type);
collect_types_from_wrapper_type(type, types);
}
static void
collect_types_from_reference_type(const_tree type, typeset &types)
{
- assert_is_type(type, REFERENCE_TYPE);
+ assert_is_complete_type(type, REFERENCE_TYPE);
collect_types_from_wrapper_type(type, types);
}
static void
collect_types_from_array_type(const_tree type, typeset &types)
{
- assert_is_type(type, ARRAY_TYPE);
+ assert_is_complete_type(type, ARRAY_TYPE);
collect_types_from_wrapper_type(type, types);
}
@@ -133,6 +136,7 @@ static void
collect_types_from_function_or_method_type(const_tree type, typeset &types)
{
gcc_assert(type);
+ assert_is_complete(type);
const enum tree_code code = TREE_CODE(type);
const bool is_function = FUNCTION_TYPE == code;
const bool is_method = METHOD_TYPE == code;
@@ -155,14 +159,14 @@ collect_types_from_function_or_method_type(const_tree type, typeset &types)
static void
collect_types_from_function_type(const_tree type, typeset &types)
{
- assert_is_type(type, FUNCTION_TYPE);
+ assert_is_complete_type(type, FUNCTION_TYPE);
collect_types_from_function_or_method_type(type, types);
}
static void
collect_types_from_method_type(const_tree type, typeset &types)
{
- assert_is_type(type, METHOD_TYPE);
+ assert_is_complete_type(type, METHOD_TYPE);
collect_types_from_function_or_method_type(type, types);
}
@@ -231,7 +235,7 @@ collect_types(const_tree type, typeset &types)
case QUAL_UNION_TYPE:
case LANG_TYPE:
default:
- //log("%s\n", get_tree_code_name(code));
+ log("%s\n", get_tree_code_name(code));
gcc_unreachable();
break;
}
diff --git a/gcc/ipa-hello-world.c b/gcc/ipa-hello-world.c
index e3ea729bbb9..4f2622cec5f 100644
--- a/gcc/ipa-hello-world.c
+++ b/gcc/ipa-hello-world.c
@@ -66,16 +66,6 @@ static type_comparison_func_t comparisons[type_comparisons] = {
};
}
-inline void
-log(const char* const fmt, ...)
-{
- if (!dump_file) return;
-
- va_list args;
- va_start(args, fmt);
- vfprintf(dump_file, fmt, args);
- va_end(args);
-}
static void
collect_types_from_cnode_decl(cgraph_node *cnode, typeset &types)
@@ -137,7 +127,7 @@ collect_types_from_functions_with_gimple_body(cgraph_node *cnode, typeset &types
gcc_assert(cnode);
collect_types_from_cnode_decl(cnode, types);
collect_types_from_cnode_locals(cnode, types);
- collect_types_from_cnode_ssa_names(cnode, types);
+ //collect_types_from_cnode_ssa_names(cnode, types);
}
static void
diff --git a/gcc/name-types.c b/gcc/name-types.c
index 44ff4021153..5629cc40a7f 100644
--- a/gcc/name-types.c
+++ b/gcc/name-types.c
@@ -74,7 +74,7 @@ type_to_string_get_field_name(const_tree field)
const_tree decl_name = DECL_NAME(field);
if (!decl_name) return std::string("");
- const char* identifier = IDENTIFIER_POINTER(field);
+ const char* identifier = IDENTIFIER_POINTER(decl_name);
return std::string(identifier);
}
diff --git a/gcc/passes.def b/gcc/passes.def
index 98195c02f66..442e1e7b0e1 100644
--- a/gcc/passes.def
+++ b/gcc/passes.def
@@ -149,6 +149,7 @@ along with GCC; see the file COPYING3. If not see
NEXT_PASS (pass_ipa_profile);
NEXT_PASS (pass_ipa_icf);
NEXT_PASS (pass_ipa_devirt);
+ NEXT_PASS (pass_ipa_hello_world);
NEXT_PASS (pass_ipa_cp);
NEXT_PASS (pass_ipa_sra);
NEXT_PASS (pass_ipa_cdtor_merge);
@@ -171,7 +172,6 @@ along with GCC; see the file COPYING3. If not see
compiled unit. */
INSERT_PASSES_AFTER (all_late_ipa_passes)
NEXT_PASS (pass_materialize_all_clones);
- NEXT_PASS (pass_ipa_hello_world);
NEXT_PASS (pass_ipa_pta);
NEXT_PASS (pass_omp_simd_clone);
TERMINATE_PASS_LIST (all_late_ipa_passes)
diff --git a/gcc/testsuite/gcc.dg/ipa/type-playground-00.c b/gcc/testsuite/gcc.dg/ipa/type-playground-00.c
index 21180e53a4a..708b4d9d785 100644
--- a/gcc/testsuite/gcc.dg/ipa/type-playground-00.c
+++ b/gcc/testsuite/gcc.dg/ipa/type-playground-00.c
@@ -1,5 +1,5 @@
-/* { dg-do run } */
-/* { dg-options "-fipa-hello-world -fdump-ipa-hello-world -ftp-comparison-functions=EQ_POINTER -ftp-types-compared=int " } */
+/* { dg-do link } */
+/* { dg-options "-flto -fipa-hello-world -fdump-ipa-hello-world -ftp-comparison-functions=EQ_POINTER -ftp-types-compared=int " } */
int
main ()
@@ -17,5 +17,5 @@ main ()
// evaluates to false
-/* { dg-final { scan-ipa-dump "0,32:integer_type x 0,32:integer_type = f," "hello-world" } } */
+/* { dg-final { scan-wpa-ipa-dump "0,32:integer_type x 0,32:integer_type = t," "hello-world" } } */
diff --git a/gcc/testsuite/gcc.dg/ipa/type-playground-01.c b/gcc/testsuite/gcc.dg/ipa/type-playground-01.c
new file mode 100644
index 00000000000..4abd3aa6161
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/type-playground-01.c
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+/* { dg-options "-flto -fipa-hello-world -fdump-ipa-hello-world -ftp-comparison-functions=EQ_STRUCTURAL -ftp-types-compared=astruct_s" } */
+
+struct astruct_s {
+ struct astruct_s* a;
+};
+
+int
+main(int argc, char* argv)
+{
+ struct astruct_s a;
+}
+
+// This is proof that an incomplete type cannot be compared
+// via structural equality.
+
+// 0,64:astruct_s {0,64:astruct_s {}*;} x 0,0:astruct_s {} = f,
+// I am not an expert on regex
+/* { dg-final { scan-wpa-ipa-dump "0,64:astruct_s .0,64:astruct_s ..... x 0,0:astruct_s .. = f," "hello-world" } } */
diff --git a/gcc/types-inlines.h b/gcc/types-inlines.h
index 24bd23dddc9..1532ef198e8 100644
--- a/gcc/types-inlines.h
+++ b/gcc/types-inlines.h
@@ -1,5 +1,25 @@
#pragma once
+
+inline void
+log(const char* const fmt, ...)
+{
+ if (!dump_file) return;
+
+ va_list args;
+ va_start(args, fmt);
+ vfprintf(dump_file, fmt, args);
+ va_end(args);
+}
+
+inline void
+assert_is_complete(const_tree a)
+{
+ //gcc_assert(a);
+ //const_tree type_size = TYPE_SIZE(a);
+ //gcc_assert(NULL_TREE != type_size);
+}
+
inline void
assert_is_type(const_tree a, const enum tree_code expected_code)
{
@@ -9,3 +29,9 @@ assert_is_type(const_tree a, const enum tree_code expected_code)
gcc_assert(eq_codes);
}
+inline void
+assert_is_complete_type(const_tree a, const enum tree_code expected_code)
+{
+ //assert_is_complete(a);
+ assert_is_type(a, expected_code);
+}
diff --git a/test.sh b/test.sh
new file mode 100755
index 00000000000..d649022ea72
--- /dev/null
+++ b/test.sh
@@ -0,0 +1,3 @@
+pushd ${HOME}/code/gcc-build
+make check-gcc RUNTESTFLAGS="ipa.exp"
+popd