aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2019-10-03 00:32:56 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2019-10-03 00:32:56 +0200
commit1006c9d4395a939820df76f37c7b085a4a1a003f (patch)
tree973f74c8b74c3df61c1379ee1c6ebc66d0fa048a /gcc
parent276a52d5566487fa53bcf34f24290362a10ac316 (diff)
downloadgcc-1006c9d4395a939820df76f37c7b085a4a1a003f.zip
gcc-1006c9d4395a939820df76f37c7b085a4a1a003f.tar.gz
gcc-1006c9d4395a939820df76f37c7b085a4a1a003f.tar.bz2
constexpr.c (cxx_eval_constant_expression): If not skipping upon entry to body...
* constexpr.c (cxx_eval_constant_expression) <case CLEANUP_STMT>: If not skipping upon entry to body, run cleanup with the same *jump_target as it started to run the cleanup even if the body returns, breaks or continues. (potential_constant_expression_1): Allow CLEANUP_STMT. * g++.dg/ext/constexpr-attr-cleanup1.C: New test. From-SVN: r276494
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/constexpr.c27
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/g++.dg/ext/constexpr-attr-cleanup1.C30
4 files changed, 60 insertions, 7 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index f2c1aa2..7279062 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,11 @@
2019-10-03 Jakub Jelinek <jakub@redhat.com>
+ * constexpr.c (cxx_eval_constant_expression) <case CLEANUP_STMT>: If
+ not skipping upon entry to body, run cleanup with the same *jump_target
+ as it started to run the cleanup even if the body returns, breaks or
+ continues.
+ (potential_constant_expression_1): Allow CLEANUP_STMT.
+
* constexpr.c (cxx_eval_store_expression): Formatting fix. Handle
const_object_being_modified with array type.
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index a6a55b9..2008793 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -4899,14 +4899,21 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
break;
case CLEANUP_STMT:
- r = cxx_eval_constant_expression (ctx, CLEANUP_BODY (t), lval,
+ {
+ tree initial_jump_target = jump_target ? *jump_target : NULL_TREE;
+ r = cxx_eval_constant_expression (ctx, CLEANUP_BODY (t), lval,
+ non_constant_p, overflow_p,
+ jump_target);
+ if (!CLEANUP_EH_ONLY (t) && !*non_constant_p)
+ /* Also evaluate the cleanup. If we weren't skipping at the
+ start of the CLEANUP_BODY, change jump_target temporarily
+ to &initial_jump_target, so that even a return or break or
+ continue in the body doesn't skip the cleanup. */
+ cxx_eval_constant_expression (ctx, CLEANUP_EXPR (t), true,
non_constant_p, overflow_p,
- jump_target);
- if (!CLEANUP_EH_ONLY (t) && !*non_constant_p)
- /* Also evaluate the cleanup. */
- cxx_eval_constant_expression (ctx, CLEANUP_EXPR (t), true,
- non_constant_p, overflow_p,
- jump_target);
+ jump_target ? &initial_jump_target
+ : NULL);
+ }
break;
/* These differ from cxx_eval_unary_expression in that this doesn't
@@ -6975,6 +6982,12 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
return true;
case CLEANUP_STMT:
+ if (!RECUR (CLEANUP_BODY (t), any))
+ return false;
+ if (!CLEANUP_EH_ONLY (t) && !RECUR (CLEANUP_EXPR (t), any))
+ return false;
+ return true;
+
case EMPTY_CLASS_EXPR:
case PREDICT_EXPR:
return false;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d321861..b9fcbb0 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2019-10-03 Jakub Jelinek <jakub@redhat.com>
+
+ * g++.dg/ext/constexpr-attr-cleanup1.C: New test.
+
2019-10-02 Martin Sebor <msebor@redhat.com>
PR tree-optimization/80936
diff --git a/gcc/testsuite/g++.dg/ext/constexpr-attr-cleanup1.C b/gcc/testsuite/g++.dg/ext/constexpr-attr-cleanup1.C
new file mode 100644
index 0000000..2c4f61a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/constexpr-attr-cleanup1.C
@@ -0,0 +1,30 @@
+// { dg-do compile { target c++2a } }
+
+constexpr void
+cleanup (int *x)
+{
+ if (x)
+ asm (""); // { dg-error "inline assembly is not a constant expression" }
+} // { dg-message "only unevaluated inline assembly is allowed in a 'constexpr' function" "" { target *-*-* } .-1 }
+
+constexpr void
+cleanup2 (int *x)
+{
+}
+
+constexpr bool
+foo ()
+{
+ int a __attribute__((cleanup (cleanup))) = 1;
+ return true;
+}
+
+constexpr bool
+bar ()
+{
+ int a __attribute__((cleanup (cleanup2))) = 1;
+ return true;
+}
+
+constexpr auto x = foo (); // { dg-message "in 'constexpr' expansion of" }
+constexpr auto y = bar ();