This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch: PR preprocessor/28165
- From: Tom Tromey <tromey at redhat dot com>
- To: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: 29 Dec 2006 12:00:52 -0700
- Subject: Patch: PR preprocessor/28165
- Reply-to: tromey at redhat dot com
This patch fixes PR preprocessor/28165.
The bug here is that _Pragma("GCC system_header") does not warn when
"#pragma GCC system_header" would have warned.
The problem is that destringize_and_run pushes a new buffer in order
to parse the string argument to _Pragma. This new buffer has a
non-null 'prev' pointer. However, the rest of cpp uses 'prev==NULL'
to check to see whether the current file is the outermost.
I fixed this by changing the test for outermost file to look at the
line table's depth instead. Also I moved this test into a new
function, as I think this is clearer.
Bootstrapped and regression tested on x86 FC6. New test case
included.
Ok?
Tom
:ADDPATCH preprocessor:
libcpp
2006-12-28 Tom Tromey <tromey@redhat.com>
PR preprocessor/28165:
* internal.h (cpp_in_primary_file): New function.
* directives.c (do_include_next): Use cpp_in_primary_file.
(do_pragma_once): Likewise.
(do_pragma_system_header): Likewise.
gcc/testsuite
2006-12-29 Tom Tromey <tromey@redhat.com>
PR preprocessor/28165:
* gcc.dg/cpp/pr28165.c: New file.
Index: libcpp/internal.h
===================================================================
--- libcpp/internal.h (revision 120244)
+++ libcpp/internal.h (working copy)
@@ -1,5 +1,5 @@
/* Part of CPP library.
- Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
+ Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
@@ -488,6 +488,13 @@
#define CPP_PEDANTIC(PF) CPP_OPTION (PF, pedantic)
#define CPP_WTRADITIONAL(PF) CPP_OPTION (PF, warn_traditional)
+static inline int cpp_in_primary_file (cpp_reader *);
+static inline int
+cpp_in_primary_file (cpp_reader *pfile)
+{
+ return pfile->line_table->depth == 1;
+}
+
/* In errors.c */
extern int _cpp_begin_message (cpp_reader *, int,
source_location, unsigned int);
Index: libcpp/directives.c
===================================================================
--- libcpp/directives.c (revision 120244)
+++ libcpp/directives.c (working copy)
@@ -772,7 +780,7 @@
/* If this is the primary source file, warn and use the normal
search logic. */
- if (! pfile->buffer->prev)
+ if (cpp_in_primary_file (pfile))
{
cpp_error (pfile, CPP_DL_WARNING,
"#include_next in primary source file");
@@ -1346,7 +1354,7 @@
static void
do_pragma_once (cpp_reader *pfile)
{
- if (pfile->buffer->prev == NULL)
+ if (cpp_in_primary_file (pfile))
cpp_error (pfile, CPP_DL_WARNING, "#pragma once in main file");
check_eol (pfile);
@@ -1396,9 +1404,7 @@
static void
do_pragma_system_header (cpp_reader *pfile)
{
- cpp_buffer *buffer = pfile->buffer;
-
- if (buffer->prev == 0)
+ if (cpp_in_primary_file (pfile))
cpp_error (pfile, CPP_DL_WARNING,
"#pragma system_header ignored outside include file");
else
Index: gcc/testsuite/gcc.dg/cpp/pr28165.c
===================================================================
--- gcc/testsuite/gcc.dg/cpp/pr28165.c (revision 0)
+++ gcc/testsuite/gcc.dg/cpp/pr28165.c (revision 0)
@@ -0,0 +1,6 @@
+/* Copyright (C) 2006 Free Software Foundation, Inc. */
+/* PR preprocessor/28165 */
+
+/* { dg-do preprocess } */
+#pragma GCC system_header /* { dg-warning "system_header" "ignored" } */
+_Pragma ("GCC system_header") /* { dg-warning "system_header" "ignored" } */