diff mbox

Set expr loc safely (PR c++/58516)

Message ID 20130924163558.GE12296@redhat.com
State New
Headers show

Commit Message

Marek Polacek Sept. 24, 2013, 4:35 p.m. UTC
I admit I haven't spent much time on this, but it seems we should just
check whether we can set the expr location before actually setting it...

Regtested/bootstrapped on x86_64-linux, ok for trunk?

2013-09-24  Marek Polacek  <polacek@redhat.com>

	PR c++/58516
cp/
	* semantics.c (finish_transaction_stmt): Set location only when the
	expression can have location.

testsuite/
	* g++.dg/tm/pr58516.C: New test.


	Marek

Comments

Paolo Carlini Sept. 24, 2013, 5 p.m. UTC | #1
Hi,

On 9/24/13 11:35 AM, Marek Polacek wrote:
> I admit I haven't spent much time on this, but it seems we should just
> check whether we can set the expr location before actually setting it...
>
> Regtested/bootstrapped on x86_64-linux, ok for trunk?
Two minor nits (assuming the general idea makes sense, first blush it does).

First, solicited by the ChangeLog entry too and given that non-null 
expression trees can always have locations, I wonder if we shouldn't 
check EXPR_P instead, it seems more direct, unless we really fear that 
body could be NULL_TREE. I would also phrase in a negative form the 
comment before the check, like "This may not be true when..."

Second, I'm pretty sure about this one, I think we are standardizing on 
c++11 for testcases, by now c++0x is essentially legacy.

Paolo.
diff mbox

Patch

--- gcc/cp/semantics.c.mp	2013-09-24 17:24:59.907548551 +0200
+++ gcc/cp/semantics.c	2013-09-24 17:25:04.251564960 +0200
@@ -5199,7 +5199,9 @@  finish_transaction_stmt (tree stmt, tree
     {
       tree body = build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt),
 					     noex);
-      SET_EXPR_LOCATION (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt)));
+      /* This may occur when the STATEMENT_LIST is empty.  */
+      if (CAN_HAVE_LOCATION_P (body))
+        SET_EXPR_LOCATION (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt)));
       TREE_SIDE_EFFECTS (body) = 1;
       TRANSACTION_EXPR_BODY (stmt) = body;
     }
--- gcc/testsuite/g++.dg/tm/pr58516.C.mp	2013-09-24 17:27:08.859055542 +0200
+++ gcc/testsuite/g++.dg/tm/pr58516.C	2013-09-24 17:28:29.829354635 +0200
@@ -0,0 +1,7 @@ 
+// { dg-do compile }
+// { dg-options "-std=c++0x -fgnu-tm" }
+
+void foo()
+{
+  __transaction_atomic noexcept(false) {}
+}