aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.h
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2022-02-06 11:16:29 +0100
committerJakub Jelinek <jakub@redhat.com>2022-02-06 11:16:29 +0100
commitf9e900ce9b17dc7d3a3809d0b0648ebe529a87c5 (patch)
tree262e687be417a4cc508b4138e66606766d593aa9 /gcc/fold-const.h
parent661109b024488eed91cc9006da25e9b8d795d409 (diff)
downloadgcc-f9e900ce9b17dc7d3a3809d0b0648ebe529a87c5.zip
gcc-f9e900ce9b17dc7d3a3809d0b0648ebe529a87c5.tar.gz
gcc-f9e900ce9b17dc7d3a3809d0b0648ebe529a87c5.tar.bz2
c++: Further address_compare fixes [PR89074]
This patch introduces folding_cxx_constexpr, folding_initializer is used for both C and C++ initializer/constant expression folding and enables more optimizations over what we do normally at runtime, while folding_cxx_constexpr is used only during C++ constant expression folding and disables some optimizations. The patch improves STRING_CST vs. STRING_CST folding, for folding_initializer FUNCTION_DECL vs. FUNCTION_DECL folding, disables some optimizations like is_global_var != is_global_var or STRING_CST vs. DECL_P for folding_cxx_constexpr etc. 2022-02-06 Jakub Jelinek <jakub@redhat.com> PR c++/89074 PR c++/104033 * fold-const.h (folding_initializer): Adjust comment. (folding_cxx_constexpr): Declare. * fold-const.cc (folding_initializer): Adjust comment. (folding_cxx_constexpr): New variable. (address_compare): Restrict the decl vs. STRING_CST or vice versa or STRING_CST vs. STRING_CST or is_global_var != is_global_var optimizations to !folding_cxx_constexpr. Punt for FUNCTION_DECLs with non-zero offsets. If folding_initializer, assume non-aliased functions have non-zero size and have different addresses. For folding_cxx_constexpr, punt on comparisons of start of some object and end of another one, regardless whether it is a decl or string literal. Also punt for folding_cxx_constexpr on STRING_CST vs. STRING_CST comparisons if the two literals could be overlapping. * constexpr.cc (cxx_eval_binary_expression): Temporarily set folding_cxx_constexpr. * g++.dg/cpp1y/constexpr-89074-3.C: New test.
Diffstat (limited to 'gcc/fold-const.h')
-rw-r--r--gcc/fold-const.h11
1 files changed, 9 insertions, 2 deletions
diff --git a/gcc/fold-const.h b/gcc/fold-const.h
index d36bfc8..f217598 100644
--- a/gcc/fold-const.h
+++ b/gcc/fold-const.h
@@ -20,9 +20,16 @@ along with GCC; see the file COPYING3. If not see
#ifndef GCC_FOLD_CONST_H
#define GCC_FOLD_CONST_H
-/* Non-zero if we are folding constants inside an initializer; zero
- otherwise. */
+/* Nonzero if we are folding constants inside an initializer or a C++
+ manifestly-constant-evaluated context; zero otherwise.
+ Should be used when folding in initializer enables additional
+ optimizations. */
extern int folding_initializer;
+/* Nonzero if we are folding C++ manifestly-constant-evaluated context; zero
+ otherwise.
+ Should be used when certain constructs shouldn't be optimized
+ during folding in that context. */
+extern bool folding_cxx_constexpr;
/* Convert between trees and native memory representation. */
extern int native_encode_expr (const_tree, unsigned char *, int, int off = -1);