public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Alex Coplan <acoplan@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ARM/heads/morello)] cp: Generate built-in overload candidates for INTCAP_TYPE Date: Wed, 24 Aug 2022 13:29:03 +0000 (GMT) [thread overview] Message-ID: <20220824132903.76E40385274F@sourceware.org> (raw) https://gcc.gnu.org/g:ec6e1327c229b91f5339c99603212e005b0b5a43 commit ec6e1327c229b91f5339c99603212e005b0b5a43 Author: Alex Coplan <alex.coplan@arm.com> 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<tree,va_gc> &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; }
reply other threads:[~2022-08-24 13:29 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220824132903.76E40385274F@sourceware.org \ --to=acoplan@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).