aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2024-02-01 16:11:43 -0500
committerMarek Polacek <polacek@redhat.com>2024-02-01 16:21:36 -0500
commit8efcdbf59bfed2b888db7def16c7641f26927260 (patch)
tree096f5de0a9054c6f1f756fda823b38f234e54b5e
parent44764984cf24e27cf7756cffd197283b9c62db8b (diff)
downloadgcc-8efcdbf59bfed2b888db7def16c7641f26927260.zip
gcc-8efcdbf59bfed2b888db7def16c7641f26927260.tar.gz
gcc-8efcdbf59bfed2b888db7def16c7641f26927260.tar.bz2
c++: -Wdangling-reference tweak to unbreak aarch64
My recent -Wdangling-reference change to not warn on std::span-like classes unfortunately caused a new warning: extending reference_like_class_p also opens the door to new warnings since we use reference_like_class_p for checking the return type of the function: either it must be a reference or a reference_like_class_p. We can consider even non-templates as std::span-like to get rid of the warning here. gcc/cp/ChangeLog: * call.cc (reference_like_class_p): Consider even non-templates for std::span-like classes. gcc/ChangeLog: * doc/invoke.texi: Update -Wdangling-reference documentation. gcc/testsuite/ChangeLog: * g++.dg/warn/Wdangling-reference21.C: New test.
-rw-r--r--gcc/cp/call.cc8
-rw-r--r--gcc/doc/invoke.texi2
-rw-r--r--gcc/testsuite/g++.dg/warn/Wdangling-reference21.C44
3 files changed, 48 insertions, 6 deletions
diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 42cbd0d..1dac147 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -14082,8 +14082,8 @@ reference_like_class_p (tree ctype)
return true;
}
- /* Avoid warning if CTYPE looks like std::span: it's a class template,
- has a T* member, and a trivial destructor. For example,
+ /* Avoid warning if CTYPE looks like std::span: it has a T* member and
+ a trivial destructor. For example,
template<typename T>
struct Span {
@@ -14092,9 +14092,7 @@ reference_like_class_p (tree ctype)
};
is considered std::span-like. */
- if (NON_UNION_CLASS_TYPE_P (ctype)
- && CLASSTYPE_TEMPLATE_INSTANTIATION (ctype)
- && TYPE_HAS_TRIVIAL_DESTRUCTOR (ctype))
+ if (NON_UNION_CLASS_TYPE_P (ctype) && TYPE_HAS_TRIVIAL_DESTRUCTOR (ctype))
for (tree field = next_aggregate_field (TYPE_FIELDS (ctype));
field; field = next_aggregate_field (DECL_CHAIN (field)))
if (TYPE_PTR_P (TREE_TYPE (field)))
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 14730c0..e9c691d 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -3929,7 +3929,7 @@ struct Span @{
@};
@end smallexample
-as @code{std::span}-like; that is, the class is a non-union class template
+as @code{std::span}-like; that is, the class is a non-union class
that has a pointer data member and a trivial destructor.
This warning is enabled by @option{-Wall}.
diff --git a/gcc/testsuite/g++.dg/warn/Wdangling-reference21.C b/gcc/testsuite/g++.dg/warn/Wdangling-reference21.C
new file mode 100644
index 0000000..e1b6e3d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wdangling-reference21.C
@@ -0,0 +1,44 @@
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wdangling-reference" }
+// Reduced from config/aarch64/aarch64-early-ra.cc.
+
+template <typename T> struct array_slice {
+ using iterator = T *;
+ iterator begin();
+ iterator end();
+ iterator m_base;
+};
+
+struct allocno_group_info { };
+
+char recog_data_2;
+int record_constraints_op;
+struct early_ra {
+ using operand_mask = int;
+ struct allocno_info {
+ int is_earlyclobbered;
+ };
+ struct allocno_subgroup {
+ array_slice<allocno_info> allocnos();
+ allocno_group_info *group;
+ };
+ allocno_subgroup get_allocno_subgroup(int);
+ void record_constraints();
+};
+void early_ra::record_constraints() {
+ operand_mask earlyclobber_operands, matched_operands, unmatched_operands,
+ matches_operands, op_mask = operand_mask();
+ auto record_operand = [&](int, int) {
+ operand_mask overlaps;
+ matches_operands |= overlaps;
+ };
+ for (int opno = 0; recog_data_2; ++opno) {
+ operand_mask op_mask = earlyclobber_operands |= op_mask;
+ if (0)
+ record_operand(1, 0);
+ }
+ if (op_mask || (matched_operands & unmatched_operands && 0))
+ for (auto &allocno : get_allocno_subgroup(record_constraints_op).allocnos())
+ allocno.is_earlyclobbered = true;
+}
+