diff options
author | Jason Merrill <jason@redhat.com> | 2023-05-01 17:41:44 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2023-05-02 16:24:15 -0400 |
commit | 4b8d0d4d7fd245ef85c7801e7838845502a5a61d (patch) | |
tree | ee8437c91f6467f278d48bb59a956ae1ce330b9f /gcc/cp | |
parent | bc24c51c0ccd64617864897ad071c98004ffc0a4 (diff) | |
download | gcc-4b8d0d4d7fd245ef85c7801e7838845502a5a61d.zip gcc-4b8d0d4d7fd245ef85c7801e7838845502a5a61d.tar.gz gcc-4b8d0d4d7fd245ef85c7801e7838845502a5a61d.tar.bz2 |
c++: std::variant slow to compile [PR109678]
Here, when dealing with a class with a complex subobject structure, we would
try and fail to find the relevant FIELD_DECL for an empty base before giving
up. And we would do this at each level, in a combinatorially problematic
way. Instead, we should check for an empty base first.
PR c++/109678
gcc/cp/ChangeLog:
* constexpr.cc (cxx_fold_indirect_ref_1): Handle empty base first.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1z/variant1.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/constexpr.cc | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index d109776..37d1c44 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -5446,6 +5446,19 @@ cxx_fold_indirect_ref_1 (const constexpr_ctx *ctx, location_t loc, tree type, return ret; } } + + /* Handle conversion to an empty base class, which is represented with a + NOP_EXPR. Do this before spelunking into the non-empty subobjects, + which is likely to be a waste of time (109678). */ + if (is_empty_class (type) + && CLASS_TYPE_P (optype) + && DERIVED_FROM_P (type, optype)) + { + if (empty_base) + *empty_base = true; + return op; + } + for (tree field = TYPE_FIELDS (optype); field; field = DECL_CHAIN (field)) if (TREE_CODE (field) == FIELD_DECL @@ -5468,16 +5481,6 @@ cxx_fold_indirect_ref_1 (const constexpr_ctx *ctx, location_t loc, tree type, return ret; } } - /* Also handle conversion to an empty base class, which - is represented with a NOP_EXPR. */ - if (is_empty_class (type) - && CLASS_TYPE_P (optype) - && DERIVED_FROM_P (type, optype)) - { - if (empty_base) - *empty_base = true; - return op; - } } return NULL_TREE; |