* c-pragma.c (handle_pragma_message): New function.
(init_pragma): Register handle_pragma_message.
* doc/extend.texi (Diagnostic Pragmas): Added #pragma message
documentation.
* gcc.dg/pragma-message.c: New.
From-SVN: r138206
+2008-07-28 Simon Baldwin <simonb@google.com>
+
+ * c-pragma.c (handle_pragma_message): New function.
+ (init_pragma): Register handle_pragma_message.
+ * doc/extend.texi (Diagnostic Pragmas): Added #pragma message
+ documentation.
+
2008-07-27 Victor Kaplansky <victork@il.ibm.com>
PR tree-optimization/35252
}
}
+/* Print a plain user-specified message. */
+
+static void
+handle_pragma_message (cpp_reader *ARG_UNUSED(dummy))
+{
+ enum cpp_ttype token;
+ tree x, message = 0;
+
+ token = pragma_lex (&x);
+ if (token == CPP_OPEN_PAREN)
+ {
+ token = pragma_lex (&x);
+ if (token == CPP_STRING)
+ message = x;
+ else
+ GCC_BAD ("expected a string after %<#pragma message%>");
+ if (pragma_lex (&x) != CPP_CLOSE_PAREN)
+ GCC_BAD ("malformed %<#pragma message%>, ignored");
+ }
+ else if (token == CPP_STRING)
+ message = x;
+ else
+ GCC_BAD ("expected a string after %<#pragma message%>");
+
+ gcc_assert (message);
+
+ if (pragma_lex (&x) != CPP_EOF)
+ warning (OPT_Wpragmas, "junk at end of %<#pragma message%>");
+
+ if (TREE_STRING_LENGTH (message) > 1)
+ inform ("#pragma message: %s", TREE_STRING_POINTER (message));
+}
+
/* A vector of registered pragma callbacks. */
DEF_VEC_O (pragma_handler);
c_register_pragma_with_expansion (0, "redefine_extname", handle_pragma_redefine_extname);
c_register_pragma (0, "extern_prefix", handle_pragma_extern_prefix);
+ c_register_pragma_with_expansion (0, "message", handle_pragma_message);
+
#ifdef REGISTER_TARGET_PRAGMAS
REGISTER_TARGET_PRAGMAS ();
#endif
@end table
+GCC also offers a simple mechanism for printing messages during
+compilation.
+
+@table @code
+@item #pragma message @var{string}
+@cindex pragma, diagnostic
+
+Prints @var{string} as a compiler message on compilation. The message
+is informational only, and is neither a compilation warning nor an error.
+
+@smallexample
+#pragma message "Compiling " __FILE__ "..."
+@end smallexample
+
+@var{string} may be parenthesized, and is printed with location
+information. For example,
+
+@smallexample
+#define DO_PRAGMA(x) _Pragma (#x)
+#define TODO(x) DO_PRAGMA(message ("TODO - " #x))
+
+TODO(Remember to fix this)
+@end smallexample
+
+prints @samp{/tmp/file.c:4: note: #pragma message:
+TODO - Remember to fix this}.
+
+@end table
+
@node Visibility Pragmas
@subsection Visibility Pragmas
+2008-07-28 Simon Baldwin <simonb@google.com>
+
+ * gcc.dg/pragma-message.c: New.
+
2008-07-27 Victor Kaplansky <victork@il.ibm.com>
PR tree-optimization/35252
--- /dev/null
+/* Test that #pragma message "..." writes compiler messages. */
+
+#pragma message /* { dg-warning "expected a string" } */
+#pragma message 0 /* { dg-warning "expected a string" } */
+#pragma message id /* { dg-warning "expected a string" } */
+#pragma message ( /* { dg-warning "expected a string" } */
+#pragma message (0 /* { dg-warning "expected a string" } */
+#pragma message (id /* { dg-warning "expected a string" } */
+#pragma message () /* { dg-warning "expected a string" } */
+#pragma message (0) /* { dg-warning "expected a string" } */
+#pragma message (id) /* { dg-warning "expected a string" } */
+
+/* gcc prefixes '#pragma message ...' output with filename and line number,
+ then 'note: #pragma message: ', allowing dg-message to check output.
+ If unexpected pragma messages are printed (anything not caught by a
+ matching dg-message), dejagnu will report these as excess errors. */
+
+#pragma message "
+/* { dg-error "missing terminating" "" { target *-*-* } 18 } */
+/* { dg-warning "expected a string" "" { target *-*-* } 18 } */
+#pragma message "Bad 1
+/* { dg-error "missing terminating" "" { target *-*-* } 21 } */
+/* { dg-warning "expected a string" "" { target *-*-* } 21 } */
+#pragma message ("Bad 2
+/* { dg-error "missing terminating" "" { target *-*-* } 24 } */
+/* { dg-warning "expected a string" "" { target *-*-* } 24 } */
+#pragma message ("Bad 3"
+/* { dg-warning "malformed '#pragma message" "" { target *-*-* } 27 } */
+
+#pragma message "" junk
+/* { dg-warning "junk at end of '#pragma message'" "" { target *-*-* } 30 } */
+
+#pragma message ("") junk
+/* { dg-warning "junk at end of '#pragma message'" "" { target *-*-* } 33 } */
+
+#pragma message "" /* No output expected for empty messages. */
+#pragma message ("")
+
+#pragma message "Okay 1" /* { dg-message "Okay 1" } */
+#pragma message ("Okay 2") /* { dg-message "Okay 2" } */
+#define THREE "3"
+#pragma message ("Okay " THREE) /* { dg-message "Okay 3" } */
+
+/* Create a TODO() that prints a message on compilation. */
+#define DO_PRAGMA(x) _Pragma (#x)
+#define TODO(x) DO_PRAGMA(message ("TODO - " #x))
+TODO(Okay 4) /* { dg-message "TODO - Okay 4" } */
+
+#if 0
+#pragma message ("Not printed")
+#endif
+
+int unused; /* Silence `ISO C forbids an empty translation unit' warning. */