This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C PATCH] Warn for _Alignas + main (PR c/61077)


Joseph pointed out that we don't warn when the return type of
main or the parameter type of main have the _Atomic qualifier.
This patch adds such warning.

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

2014-05-08  Marek Polacek  <polacek@redhat.com>

	PR c/61077
c-family/
	* c-common.c (check_main_parameter_types): Warn for _Atomic-qualified
	parameter type of main.
c/
	* c-decl.c (start_function): Warn for _Atomic-qualified return type
	of main.
testsuite/
	* gcc.dg/pr61077.c: New test.

diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
index 0afe2f5..33ad250 100644
--- gcc/c-family/c-common.c
+++ gcc/c-family/c-common.c
@@ -2193,6 +2193,20 @@ check_main_parameter_types (tree decl)
       if (type == void_type_node || type == error_mark_node )
 	break;
 
+      tree t = type;
+      if (TYPE_ATOMIC (t))
+	  pedwarn (input_location, OPT_Wmain,
+		   "%<_Atomic%>-qualified parameter type %qT of %q+D",
+		   type, decl);
+      while (POINTER_TYPE_P (t))
+	{
+	  t = TREE_TYPE (t);
+	  if (TYPE_ATOMIC (t))
+	    pedwarn (input_location, OPT_Wmain,
+		     "%<_Atomic%>-qualified parameter type %qT of %q+D",
+		     type, decl);
+	}
+
       ++argct;
       switch (argct)
 	{
diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index 3abf6b9..d8631fc 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -8045,6 +8045,9 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
       if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
 	  != integer_type_node)
 	pedwarn (loc, OPT_Wmain, "return type of %qD is not %<int%>", decl1);
+      else if (TYPE_ATOMIC (TREE_TYPE (TREE_TYPE (decl1))))
+	pedwarn (loc, OPT_Wmain, "%<_Atomic%>-qualified return type of %qD",
+		 decl1);
 
       check_main_parameter_types (decl1);
 
diff --git gcc/testsuite/gcc.dg/pr61077.c gcc/testsuite/gcc.dg/pr61077.c
index e69de29..c0513f7 100644
--- gcc/testsuite/gcc.dg/pr61077.c
+++ gcc/testsuite/gcc.dg/pr61077.c
@@ -0,0 +1,12 @@
+/* PR c/61077 */
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -Wall" } */
+
+_Atomic int
+main (_Atomic int argc, _Atomic char **argv)
+/* { dg-warning "qualified return type" "return" { target *-*-* } 6 } */
+/* { dg-warning "qualified parameter type.*int" "parameter" { target *-*-* } 6 } */
+/* { dg-warning "qualified parameter type.*char" "parameter" { target *-*-* } 6 } */
+{
+  return 0;
+}

	Marek


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]