From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7810) id 76E40385274F; Wed, 24 Aug 2022 13:29:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76E40385274F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661347743; bh=4cz5+qEJPqPn32XxklD5bYfZBshf5IwnWIVJMvUdIc0=; h=From:To:Subject:Date:From; b=I/gI8KKOpaOzQvL50ExfNMcjeff4x3IHE+usrtVX1zzZAYGM4siLusuihXbpAzMkn lCYCozp4/Wm5xv6HX5jz6sWH2yWnNp8bpomyhwpWgpIQNTDUS0O80jNXECXcM9UKP8 cQRSihtUWZ/Xw3SCLG9tt/fZWLgFH7esUXLtuZ6k= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Alex Coplan To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ARM/heads/morello)] cp: Generate built-in overload candidates for INTCAP_TYPE X-Act-Checkin: gcc X-Git-Author: Alex Coplan X-Git-Refname: refs/vendors/ARM/heads/morello X-Git-Oldrev: c2b576d3d46ce698168cf650b5f6a0cd37931ef7 X-Git-Newrev: ec6e1327c229b91f5339c99603212e005b0b5a43 Message-Id: <20220824132903.76E40385274F@sourceware.org> Date: Wed, 24 Aug 2022 13:29:03 +0000 (GMT) List-Id: https://gcc.gnu.org/g:ec6e1327c229b91f5339c99603212e005b0b5a43 commit ec6e1327c229b91f5339c99603212e005b0b5a43 Author: Alex Coplan Date: Tue Aug 9 10:13:51 2022 +0100 cp: Generate built-in overload candidates for INTCAP_TYPE We were missing handling for INTCAP_TYPE in cp/call.c:add_builtin_candidate. This meant that code relying on implicit conversions from enum type to intcap type and user-defined implicit conversions to intcap type would be incorrectly rejected. This patch fixes that. gcc/cp/ChangeLog: * call.c (add_builtin_candidate): Handle INTCAP_TYPE operands. * typeck.c (cp_build_array_ref): Handle index of INTCAP_TYPE. gcc/testsuite/ChangeLog: * g++.target/aarch64/morello/intcap-overload-candidates.C: New test. Diff: --- gcc/cp/call.c | 26 ++++++++++-- gcc/cp/typeck.c | 3 ++ .../aarch64/morello/intcap-overload-candidates.C | 49 ++++++++++++++++++++++ 3 files changed, 75 insertions(+), 3 deletions(-) diff --git a/gcc/cp/call.c b/gcc/cp/call.c index f8eeac5f33f..bd5dea9ed24 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -2656,6 +2656,17 @@ add_builtin_candidate (struct z_candidate **candidates, enum tree_code code, tree type2, vec &args, tree *argtypes, int flags, tsubst_flags_t complain) { + tree orig_type1 = type1; + tree orig_type2 = type2; + + if (INTCAP_TYPE_P (type1)) + type1 = noncapability_type (type1); + if (type2 && INTCAP_TYPE_P (type2)) + type2 = noncapability_type (type2); + + tree precheck_type1 = type1; + tree precheck_type2 = type2; + switch (code) { case POSTINCREMENT_EXPR: @@ -2701,7 +2712,7 @@ add_builtin_candidate (struct z_candidate **candidates, enum tree_code code, return; if (ARITHMETIC_TYPE_P (type1) || TYPE_PTROB_P (type1)) { - type1 = build_reference_type (type1); + type1 = build_reference_type (orig_type1); break; } return; @@ -3009,7 +3020,7 @@ add_builtin_candidate (struct z_candidate **candidates, enum tree_code code, default: gcc_unreachable (); } - type1 = build_reference_type (type1); + type1 = build_reference_type (orig_type1); break; case COND_EXPR: @@ -3047,11 +3058,20 @@ add_builtin_candidate (struct z_candidate **candidates, enum tree_code code, if (ARITHMETIC_TYPE_P (type1)) break; return; - + default: gcc_unreachable (); } + /* Restore the original types if necessary. */ + if (INTCAP_TYPE_P (orig_type1) && type1 == precheck_type1) + type1 = orig_type1; + + if (orig_type2 + && INTCAP_TYPE_P (orig_type2) + && type2 == precheck_type2) + type2 = orig_type2; + /* Make sure we don't create builtin candidates with dependent types. */ bool u1 = uses_template_parms (type1); bool u2 = type2 ? uses_template_parms (type2) : false; diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 753191eff8d..31b86f96c02 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -3552,6 +3552,9 @@ cp_build_array_ref (location_t loc, tree array, tree idx, return error_mark_node; } + if (INTCAP_TYPE_P (TREE_TYPE (idx))) + idx = drop_capability (idx); + if (TREE_TYPE (array) == error_mark_node || TREE_TYPE (idx) == error_mark_node) return error_mark_node; diff --git a/gcc/testsuite/g++.target/aarch64/morello/intcap-overload-candidates.C b/gcc/testsuite/g++.target/aarch64/morello/intcap-overload-candidates.C new file mode 100644 index 00000000000..c1cfd52cefb --- /dev/null +++ b/gcc/testsuite/g++.target/aarch64/morello/intcap-overload-candidates.C @@ -0,0 +1,49 @@ +/* { dg-do compile } */ +/* Test that we generate the correct built-in overload candidates (in + the sense of [over.built]) for INTCAP_TYPES. */ +__intcap c; +struct S { + operator __intcap () { return 42; } +}; +struct Q { + operator __intcap &() { return c; } +}; +struct R { + operator long () { return 42; } +}; +enum E { + wibble = 1 +}; +__intcap f1(S s) { return +s; } +__intcap f2(S s) { return -s; } +__intcap f3(S s) { return ~s; } +int *f4(S s, int *p) { return p - s; } +__intcap f5(S s) { return s + s; } /* { dg-warning "it is not clear which should be used as the source of provenance" } */ +__intcap f6(S s) { return s * s; } /* { dg-warning "it is not clear which should be used as the source of provenance" } */ +__intcap f7(S s) { return c / s; } /* { dg-warning "it is not clear which should be used as the source of provenance" } */ +__intcap f8(Q q) { return ++q; } +__intcap f9(Q q) { return --q; } +__intcap f10(Q q) { return q++; } +__intcap f11(Q q) { return q--; } +bool f12(S s) { return s == c; } +bool f13(S s) { return s < c; } +int f14(int *p, S s) { return p[s]; } +__intcap f15(__intcap c) { return c & wibble; } +__intcap f16(__intcap c) { return c ^ wibble; } +__intcap f17(__intcap c) { return c | wibble; } +__intcap f18(__intcap c) { return c << wibble; } +__intcap f19(__intcap c) { return c >> wibble; } +__intcap f20(__intcap c, R r) { return c & r; } +void f21 (Q q) { q += 2; } +void f22 (Q q) { q -= 3; } +void f23 (Q q) { q *= 4; } +void f24 (Q q) { q /= 5; } +void f25 (Q q, S s) { q %= s; } +void f26 (Q q, S s) { q ^= s; } +void f27 (Q q) { q |= c; } +void f28 (Q q) { q &= c; } +void f29 (Q q) { q ^= c; } +void f30 (Q q, S s) { q <<= s; } +void f31 (Q q, S s) { q >>= s; } +__intcap f32 (S s, bool b) { return b ? c : s; } +__intcap f33 (S s, bool b) { return b ? s : c; }