diff mbox

C PATCH to disallow invalid arguments to __atomic_* (PR c/71514)

Message ID 20160818110043.GP7007@redhat.com
State New
Headers show

Commit Message

Marek Polacek Aug. 18, 2016, 11 a.m. UTC
As discussed in the PR, for __atomic_* functions we shouldn't accept
pointer-to-function and pointer-to-VLA as arguments.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2016-08-18  Marek Polacek  <polacek@redhat.com>

	PR c/71514
	* c-common.c (get_atomic_generic_size): Disallow pointer-to-function
	and pointer-to-VLA.

	* gcc.dg/pr71514.c: New test.


	Marek

Comments

Joseph Myers Aug. 18, 2016, 4:13 p.m. UTC | #1
On Thu, 18 Aug 2016, Marek Polacek wrote:

> As discussed in the PR, for __atomic_* functions we shouldn't accept
> pointer-to-function and pointer-to-VLA as arguments.
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?

OK.
diff mbox

Patch

diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
index d413146..22e3844 100644
--- gcc/c-family/c-common.c
+++ gcc/c-family/c-common.c
@@ -11081,6 +11081,20 @@  get_atomic_generic_size (location_t loc, tree function,
 		    function);
 	  return 0;
 	}
+      else if (TYPE_SIZE_UNIT (TREE_TYPE (type))
+	       && TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type))))
+		  != INTEGER_CST)
+	{
+	  error_at (loc, "argument %d of %qE must be a pointer to a constant "
+		    "size type", x + 1, function);
+	  return 0;
+	}
+      else if (FUNCTION_POINTER_TYPE_P (type))
+	{
+	  error_at (loc, "argument %d of %qE must not be a pointer to a "
+		    "function", x + 1, function);
+	  return 0;
+	}
       tree type_size = TYPE_SIZE_UNIT (TREE_TYPE (type));
       size = type_size ? tree_to_uhwi (type_size) : 0;
       if (size != size_0)
diff --git gcc/testsuite/gcc.dg/pr71514.c gcc/testsuite/gcc.dg/pr71514.c
index e69de29..8bfa805 100644
--- gcc/testsuite/gcc.dg/pr71514.c
+++ gcc/testsuite/gcc.dg/pr71514.c
@@ -0,0 +1,23 @@ 
+/* PR c/71514 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void
+foo ()
+{
+}
+
+int a, b;
+
+void
+fn1 (void)
+{
+  __atomic_exchange (&a, &foo, &b, __ATOMIC_RELAXED); /* { dg-error "must not be a pointer to a function" } */
+}
+
+void
+fn2 (int n)
+{
+  int arr[n];
+  __atomic_exchange (&a, &arr, &b, __ATOMIC_RELAXED); /* { dg-error "must be a pointer to a constant size type" } */
+}