do { warning (OPT_Wpragmas, gmsgid); return; } while (0)
#define GCC_BAD2(gmsgid, arg) \
do { warning (OPT_Wpragmas, gmsgid, arg); return; } while (0)
+#define GCC_BAD_AT(loc, gmsgid) \
+ do { warning_at (loc, OPT_Wpragmas, gmsgid); return; } while (0)
+#define GCC_BAD2_AT(loc, gmsgid, arg) \
+ do { warning_at (loc, OPT_Wpragmas, gmsgid, arg); return; } while (0)
struct GTY(()) align_stack {
int alignment;
static void
handle_pragma_pack (cpp_reader * ARG_UNUSED (dummy))
{
+ location_t loc;
tree x, id = 0;
int align = -1;
enum cpp_ttype token;
if (pragma_lex (&x) != CPP_OPEN_PAREN)
GCC_BAD ("missing %<(%> after %<#pragma pack%> - ignored");
- token = pragma_lex (&x);
+ token = pragma_lex (&x, &loc);
if (token == CPP_CLOSE_PAREN)
{
action = set;
else if (token == CPP_NUMBER)
{
if (TREE_CODE (x) != INTEGER_CST)
- GCC_BAD ("invalid constant in %<#pragma pack%> - ignored");
+ GCC_BAD_AT (loc, "invalid constant in %<#pragma pack%> - ignored");
align = TREE_INT_CST_LOW (x);
action = set;
if (pragma_lex (&x) != CPP_CLOSE_PAREN)
else if (!strcmp (op, "pop"))
action = pop;
else
- GCC_BAD2 ("unknown action %qE for %<#pragma pack%> - ignored", x);
+ GCC_BAD2_AT (loc, "unknown action %qE for %<#pragma pack%> - ignored",
+ x);
while ((token = pragma_lex (&x)) == CPP_COMMA)
{
- token = pragma_lex (&x);
+ token = pragma_lex (&x, &loc);
if (token == CPP_NAME && id == 0)
{
id = x;
else if (token == CPP_NUMBER && action == push && align == -1)
{
if (TREE_CODE (x) != INTEGER_CST)
- GCC_BAD ("invalid constant in %<#pragma pack%> - ignored");
+ GCC_BAD_AT (loc,
+ "invalid constant in %<#pragma pack%> - ignored");
align = TREE_INT_CST_LOW (x);
if (align == -1)
action = set;
else
GCC_BAD ("malformed %<#pragma pack%> - ignored");
- if (pragma_lex (&x) != CPP_EOF)
- warning (OPT_Wpragmas, "junk at end of %<#pragma pack%>");
+ if (pragma_lex (&x, &loc) != CPP_EOF)
+ warning_at (loc, OPT_Wpragmas, "junk at end of %<#pragma pack%>");
if (flag_pack_struct)
GCC_BAD ("%<#pragma pack%> has no effect with %<-fpack-struct%> - ignored");
static void
handle_pragma_target(cpp_reader *ARG_UNUSED(dummy))
{
+ location_t loc;
enum cpp_ttype token;
tree x;
bool close_paren_needed_p = false;
return;
}
- token = pragma_lex (&x);
+ token = pragma_lex (&x, &loc);
if (token == CPP_OPEN_PAREN)
{
close_paren_needed_p = true;
- token = pragma_lex (&x);
+ token = pragma_lex (&x, &loc);
}
if (token != CPP_STRING)
{
- GCC_BAD ("%<#pragma GCC option%> is not a string");
+ GCC_BAD_AT (loc, "%<#pragma GCC option%> is not a string");
return;
}
static void
handle_pragma_message (cpp_reader *ARG_UNUSED(dummy))
{
+ location_t loc;
enum cpp_ttype token;
tree x, message = 0;
gcc_assert (message);
- if (pragma_lex (&x) != CPP_EOF)
- warning (OPT_Wpragmas, "junk at end of %<#pragma message%>");
+ if (pragma_lex (&x, &loc) != CPP_EOF)
+ warning_at (loc, OPT_Wpragmas, "junk at end of %<#pragma message%>");
if (TREE_STRING_LENGTH (message) > 1)
inform (input_location, "%<#pragma message: %s%>",
--- /dev/null
+/* Verify that we use precise locations when emitting diagnostics
+ about pragmas. */
+
+/* { dg-do assemble } */
+/* { dg-options "-fdiagnostics-show-caret" } */
+
+/* pack ****************************************************************************/
+
+#pragma pack
+/* { dg-warning "missing '\\(' after '#pragma pack' - ignored" "" { target *-*-* } .-1 }
+ { dg-begin-multiline-output "" }
+ #pragma pack
+ ^~~~
+ { dg-end-multiline-output "" } */
+
+#pragma pack (
+/* { dg-warning "malformed '#pragma pack' - ignored" "" { target *-*-* } .-1 }
+ { dg-begin-multiline-output "" }
+ #pragma pack (
+ ^~~~
+ { dg-end-multiline-output "" } */
+
+#pragma pack (32
+/* { dg-warning "malformed '#pragma pack' - ignored" "" { target *-*-* } .-1 }
+ { dg-begin-multiline-output "" }
+ #pragma pack (32
+ ^~~~
+ { dg-end-multiline-output "" } */
+
+#pragma pack (3.14159
+/* { dg-warning "invalid constant in '#pragma pack' - ignored" "" { target *-*-* } .-1 }
+ { dg-begin-multiline-output "" }
+ #pragma pack (3.14159
+ ^~~~~~~
+ { dg-end-multiline-output "" } */
+
+#pragma pack (push, 3.14159
+/* { dg-warning "invalid constant in '#pragma pack' - ignored" "" { target *-*-* } .-1 }
+ { dg-begin-multiline-output "" }
+ #pragma pack (push, 3.14159
+ ^~~~~~~
+ { dg-end-multiline-output "" } */
+
+#pragma pack (toothbrush
+/* { dg-warning "unknown action 'toothbrush' for '#pragma pack' - ignored" "" { target *-*-* } .-1 }
+ { dg-begin-multiline-output "" }
+ #pragma pack (toothbrush
+ ^~~~~~~~~~
+ { dg-end-multiline-output "" } */
+
+#pragma pack() pyjamas
+/* { dg-warning "junk at end of '#pragma pack'" "" { target *-*-* } .-1 }
+ { dg-begin-multiline-output "" }
+ #pragma pack() pyjamas
+ ^~~~~~~
+ { dg-end-multiline-output "" } */
+
+/* target ****************************************************************************/
+
+#pragma GCC target 42
+/* { dg-warning "#pragma GCC option' is not a string" "" { target *-*-* } .-1 }
+ { dg-begin-multiline-output "" }
+ #pragma GCC target 42
+ ^~
+ { dg-end-multiline-output "" } */
+
+#pragma GCC target ( 1776
+/* { dg-warning "#pragma GCC option' is not a string" "" { target *-*-* } .-1 }
+ { dg-begin-multiline-output "" }
+ #pragma GCC target ( 1776
+ ^~~~
+ { dg-end-multiline-output "" } */
+
+/* message ****************************************************************************/
+
+#pragma message "foo" int
+/* { dg-warning "junk at end of '#pragma message'" "" { target *-*-* } .-1 }
+ { dg-message "'#pragma message: foo'" "" { target *-*-* } .-2 }
+ { dg-begin-multiline-output "" }
+ #pragma message "foo" int
+ ^~~
+ { dg-end-multiline-output "" }
+ { dg-begin-multiline-output "" }
+ #pragma message "foo" int
+ ^~~~~~~
+ { dg-end-multiline-output "" } */