c-pragma.c (handle_pragma_message): New function.

* 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
This commit is contained in:
Simon Baldwin 2008-07-28 11:55:11 +00:00 committed by Simon Baldwin
parent 17df49a3e9
commit 0d48657d73
5 changed files with 128 additions and 0 deletions

View File

@ -1,3 +1,10 @@
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

View File

@ -1173,6 +1173,39 @@ handle_pragma_optimize(cpp_reader *ARG_UNUSED(dummy))
}
}
/* 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);
@ -1341,6 +1374,8 @@ init_pragma (void)
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

View File

@ -11616,6 +11616,35 @@ strict control over project policies.
@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

View File

@ -1,3 +1,7 @@
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

View File

@ -0,0 +1,53 @@
/* 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. */