diff options
author | Jakub Jelinek <jakub@redhat.com> | 2016-12-06 10:22:36 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2016-12-06 10:22:36 +0100 |
commit | bf2d0849a360376182b796042fedaa018b87d605 (patch) | |
tree | 1e28303bb9807909476388958acd7617a39ca592 /gcc/fold-const-call.c | |
parent | 0d3ce69b79ab7d7ea4a2fc4ed5e983ea6efcfa69 (diff) | |
download | gcc-bf2d0849a360376182b796042fedaa018b87d605.zip gcc-bf2d0849a360376182b796042fedaa018b87d605.tar.gz gcc-bf2d0849a360376182b796042fedaa018b87d605.tar.bz2 |
re PR c++/71537 (GCC rejects consetxpr boolean conversions and comparisons on the result of pointer arithmetic.)
PR c++/71537
* fold-const-call.c (fold_const_call): Handle
CFN_BUILT_IN_{INDEX,STRCHR,RINDEX,STRRCHR}.
* g++.dg/cpp0x/constexpr-strchr.C: New test.
From-SVN: r243284
Diffstat (limited to 'gcc/fold-const-call.c')
-rw-r--r-- | gcc/fold-const-call.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/gcc/fold-const-call.c b/gcc/fold-const-call.c index e2d0eaf..439988d 100644 --- a/gcc/fold-const-call.c +++ b/gcc/fold-const-call.c @@ -1383,6 +1383,7 @@ tree fold_const_call (combined_fn fn, tree type, tree arg0, tree arg1) { const char *p0, *p1; + char c; switch (fn) { case CFN_BUILT_IN_STRSPN: @@ -1409,6 +1410,30 @@ fold_const_call (combined_fn fn, tree type, tree arg0, tree arg1) } return NULL_TREE; + case CFN_BUILT_IN_INDEX: + case CFN_BUILT_IN_STRCHR: + if ((p0 = c_getstr (arg0)) && target_char_cst_p (arg1, &c)) + { + const char *r = strchr (p0, c); + if (r == NULL) + return build_int_cst (type, 0); + return fold_convert (type, + fold_build_pointer_plus_hwi (arg0, r - p0)); + } + return NULL_TREE; + + case CFN_BUILT_IN_RINDEX: + case CFN_BUILT_IN_STRRCHR: + if ((p0 = c_getstr (arg0)) && target_char_cst_p (arg1, &c)) + { + const char *r = strrchr (p0, c); + if (r == NULL) + return build_int_cst (type, 0); + return fold_convert (type, + fold_build_pointer_plus_hwi (arg0, r - p0)); + } + return NULL_TREE; + default: return fold_const_call_1 (fn, type, arg0, arg1); } |