This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: GOLD: RFA: Fixing a coverty error for aarch64.cc
- From: Pedro Alves <palves at redhat dot com>
- To: Cary Coutant <ccoutant at gmail dot com>, Nick Clifton <nickc at redhat dot com>
- Cc: Ian Lance Taylor <iant at google dot com>, rearnsha at arm dot com, marcus dot shawcroft at arm dot com, Binutils <binutils at sourceware dot org>
- Date: Fri, 20 Jan 2017 11:49:50 +0000
- Subject: Re: GOLD: RFA: Fixing a coverty error for aarch64.cc
- Authentication-results: sourceware.org; auth=none
- References: <87h94wmk3t.fsf@redhat.com> <CAJimCsGpYNNZn4sASR_hnd8_uk+BDiFjRPqGtTOvk1H+Uf7kgg@mail.gmail.com>
I would suggest letting the compiler handle computing
array sizes. Something like the below. (Build tested
only, feel free to run with it). If you restore the
pointer with something like:
+ const static Insntype* ST_E_835769_INSNS = ST_E_843419_INSNS;
+
[...]
- // ST_E_835769 has the same stub template as ST_E_843419.
- install_insn_template_insns(ST_E_835769, ST_E_843419);
+ install_insn_template(ST_E_835769);
Then the compiler catches the problem:
src/gold/aarch64.cc:798:65: error: no matching function for call to ‘{anonymous}::Stub_template<false>::Stub_template(const Insntype*&)’
const static Stub_template<big_endian> template_##T (I##_INSNS); \
^
src/gold/aarch64.cc:802:3: note: in expansion of macro ‘install_insn_template_insns’
install_insn_template_insns(T, T)
^
src/gold/aarch64.cc:808:3: note: in expansion of macro ‘install_insn_template’
install_insn_template(ST_E_835769);
^
src/gold/aarch64.cc:711:3: note: candidate: template<long unsigned int insn_num_>{anonymous}::Stub_template<big_endian>::Stub_template(const typename {anonymous}::AArch64_insn_utilities<big_endian>::Insntype(&)[insn_num_])
Stub_template
^
src/gold/aarch64.cc:711:3: note: template argument deduction/substitution failed:
src/gold/aarch64.cc:798:65: note: mismatched types ‘const Insntype [insn_num_]’ and ‘const Insntype* {aka const unsigned int*}’
const static Stub_template<big_endian> template_##T (I##_INSNS); \
(ST_NONE_INSNS is removed because (const-expression) arrays of 0
length are not valid C++, and compilers reject them / SFINAE them
out when deciding which constructor to call.)
>From c7cd91832535b3989ec8f41a3d1eb51c7acc0ee4 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Fri, 20 Jan 2017 10:52:05 +0000
Subject: [PATCH]
---
gold/aarch64.cc | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/gold/aarch64.cc b/gold/aarch64.cc
index facbbd8..ab80472 100644
--- a/gold/aarch64.cc
+++ b/gold/aarch64.cc
@@ -703,6 +703,16 @@ enum
template<bool big_endian>
struct Stub_template
{
+ Stub_template ()
+ : insns(NULL), insn_num(0)
+ { }
+
+ template<size_t insn_num_>
+ Stub_template
+ (const typename AArch64_insn_utilities<big_endian>::Insntype (&insns_)[insn_num_])
+ : insns(insns_), insn_num(insn_num_)
+ { }
+
const typename AArch64_insn_utilities<big_endian>::Insntype* insns;
const int insn_num;
};
@@ -746,8 +756,6 @@ template<bool big_endian>
Stub_template_repertoire<big_endian>::Stub_template_repertoire()
{
// Insn array definitions.
- const static Insntype ST_NONE_INSNS[] = {};
-
const static Insntype ST_ADRP_BRANCH_INSNS[] =
{
0x90000010, /* adrp ip0, X */
@@ -784,20 +792,19 @@ Stub_template_repertoire<big_endian>::Stub_template_repertoire()
0x14000000, /* b <label> */
};
- // ST_E_835769 has the same stub template as ST_E_843419.
- const static Insntype* ST_E_835769_INSNS = ST_E_843419_INSNS;
-
-#define install_insn_template(T) \
- const static Stub_template<big_endian> template_##T = { \
- T##_INSNS, sizeof(T##_INSNS) / sizeof(T##_INSNS[0]) }; \
+#define install_insn_template_insns(T, I) \
+ const static Stub_template<big_endian> template_##T (I##_INSNS); \
this->stub_templates_[T] = &template_##T
- install_insn_template(ST_NONE);
+#define install_insn_template(T) \
+ install_insn_template_insns(T, T)
+
install_insn_template(ST_ADRP_BRANCH);
install_insn_template(ST_LONG_BRANCH_ABS);
install_insn_template(ST_LONG_BRANCH_PCREL);
install_insn_template(ST_E_843419);
- install_insn_template(ST_E_835769);
+ // ST_E_835769 has the same stub template as ST_E_843419.
+ install_insn_template_insns(ST_E_835769, ST_E_843419);
#undef install_insn_template
}
--
2.5.5