aboutsummaryrefslogtreecommitdiff
path: root/libjava/classpath
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2026-02-04 11:36:08 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2026-02-04 11:36:08 +0100
commit71c2e6c2bfcaf33227727181dffda8a3b05e4e9b (patch)
tree553f029e18bc4c8d4f0341ba520a70ce71ef658e /libjava/classpath
parent2149eda29e2628d31faf44da060139a856c47b3f (diff)
downloadgcc-71c2e6c2bfcaf33227727181dffda8a3b05e4e9b.zip
gcc-71c2e6c2bfcaf33227727181dffda8a3b05e4e9b.tar.gz
gcc-71c2e6c2bfcaf33227727181dffda8a3b05e4e9b.tar.bz2
tree: Fix up wrong-code with certain C++ default arguments [PR123818]
The following testcase is miscompiled since r0-69852-g4038c495f (at least if one can somehow arrange in C++98 to have AGGR_INIT_EXPR or any other FE specific trees nested in constructor elts for CONSTRUCTOR nested inside of default argument, if not, then since C++11 support that allows that has been implemented). The problem is that we unfortunately store default arguments in TREE_PURPOSE of TYPE_ARG_TYPES nodes of the FUNCTION/METHOD_TYPE and those are shared, with type_hash_canon used to unify them. The default arguments aren't considered in type_hash_canon_hash at all, but the equality hook considers them in type_list_equal by calling simple_cst_equal on those default arguments. That function is a tri-state, returns 0 for surely unequal, 1 for equal and -1 for "I don't know", usually because there are FE trees etc. (though, admittedly it is unclear why such distinction is done, as e.g. for VAR_DECLs etc. it sees in there it returns 0 rather than -1). Anyway, the r0-69852-g4038c495f change changed CONSTRUCTOR_ELTS from I think a tree list of elements to a vector and changed the simple_cst_equal implementation of CONSTRUCTOR from just recursing on CONSTRUCTOR_ELTS (which I think would just return -1 because I don't see simple_cst_equal having TREE_LIST nor TREE_VEC handling) to something that thinks simple_cst_equal returns a bool rather than tri-state, plus has a comment whether it should handle indexes too. So, in particular on the testcase which has in default arguments with CONSTRUCTOR inside it with AGGR_INIT_EXPR as the single element (but could be as well in multiple elements), the recursive call returns -1 for "I don't know" on the element and the function considers it the same as if it returned 1, they are equal. The following patch fixes it by calling the recursive non tail-recursive simple_cst_equal calls like everywhere else in the function, by returning what it returned if it returned <= 0 and otherwise continuing. Plus given the comment I've also implemented checking the index. The special case for FIELD_DECL is so that if both indexes are FIELD_DECLs and they are different, we don't return -1 but 0. 2026-02-04 Jakub Jelinek <jakub@redhat.com> PR c++/123818 * tree.cc (simple_cst_equal) <case CONSTRUCTOR>: Return -1 if some recursive call returns -1. Also compare indexes. * g++.dg/cpp0x/pr123818.C: New test.
Diffstat (limited to 'libjava/classpath')
0 files changed, 0 insertions, 0 deletions