[PR,tree-optimization/59149] fail on invalid arguments to flags_from_decl_or_type
diff mbox

Message ID 52AA423C.9050808@redhat.com
State New
Headers show

Commit Message

Aldy Hernandez Dec. 12, 2013, 11:09 p.m. UTC
flags_from_decl_or_type() only handles a TYPE or DECL.  Make this 
explicit instead.

I also added a check in the use in trans-mem.c, just in case.  The 
subsequent conditionals should take care of the TM case.

It would be nice if Marc Glisse could provide the testcase he mentioned 
was failing.  Either way, the attached patch doesn't hurt.

Tested on x86-64 Linux.

OK?
commit b5830c04f011d6885e3a09f50602b8f5f495a408
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Dec 9 08:10:44 2013 -0800

	PR tree-optimization/59149
    	* calls.c (flags_from_decl_or_type): Fail on non decl or type.
    	* trans-mem.c (diagnose_tm_1): Do not call flags_from_decl_or_type
    	if no type or decl.

Comments

Jeff Law Dec. 13, 2013, 5:46 a.m. UTC | #1
On 12/12/13 16:09, Aldy Hernandez wrote:
> flags_from_decl_or_type() only handles a TYPE or DECL.  Make this
> explicit instead.
>
> I also added a check in the use in trans-mem.c, just in case.  The
> subsequent conditionals should take care of the TM case.
>
> It would be nice if Marc Glisse could provide the testcase he mentioned
> was failing.  Either way, the attached patch doesn't hurt.
>
> Tested on x86-64 Linux.
>
> OK?
OK for the trunk.

jeff
Marc Glisse Dec. 13, 2013, 6:46 a.m. UTC | #2
On Thu, 12 Dec 2013, Aldy Hernandez wrote:

> flags_from_decl_or_type() only handles a TYPE or DECL.  Make this explicit 
> instead.
>
> I also added a check in the use in trans-mem.c, just in case.  The subsequent 
> conditionals should take care of the TM case.
>
> It would be nice if Marc Glisse could provide the testcase he mentioned was 
> failing.  Either way, the attached patch doesn't hurt.

The failing testcases are already in the testsuite (I don't remember which 
ones, but there were quite a few IIRC). If you add only the 
gcc_unreachable and not the other part of your patch, you should see 
several failures.

Patch
diff mbox

diff --git a/gcc/calls.c b/gcc/calls.c
index 3963bc2..2226e78 100644
--- a/gcc/calls.c
+++ b/gcc/calls.c
@@ -769,6 +769,8 @@  flags_from_decl_or_type (const_tree exp)
 	      || lookup_attribute ("transaction_pure", TYPE_ATTRIBUTES (exp))))
 	flags |= ECF_TM_PURE;
     }
+  else
+    gcc_unreachable ();
 
   if (TREE_THIS_VOLATILE (exp))
     {
diff --git a/gcc/trans-mem.c b/gcc/trans-mem.c
index b2adc3d..1603d82 100644
--- a/gcc/trans-mem.c
+++ b/gcc/trans-mem.c
@@ -677,7 +677,8 @@  diagnose_tm_1 (gimple_stmt_iterator *gsi, bool *handled_ops_p,
 	      }
 	    else if (direct_call_p)
 	      {
-		if (flags_from_decl_or_type (fn) & ECF_TM_BUILTIN)
+		if (IS_TYPE_OR_DECL_P (fn)
+		    && flags_from_decl_or_type (fn) & ECF_TM_BUILTIN)
 		  is_safe = true;
 		else if (replacement)
 		  {