summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2008-07-31 19:12:14 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2008-07-31 19:12:14 +0000
commit408c2285f14b7cb4ebcbee38be30b9cf177d0afa (patch)
treeb8d0f8b842935bf3445c936be9b262e9c8ec3c96
parent19f93b6270249e3a0a0e48011f8041fc619f32ab (diff)
downloadgcc-408c2285f14b7cb4ebcbee38be30b9cf177d0afa.tar.gz
PR preprocessor/36649
* files.c (struct report_missing_guard_data): New type. (report_missing_guard): Put paths into an array instead of printing them right away. Return 1 rather than 0. (report_missing_guard_cmp): New function. (_cpp_report_missing_guards): Sort and print paths gathered by report_missing_guard callback. * gcc.dg/pch/cpp-3.hs: Add include guards. * gcc.dg/pch/cpp-3a.h: Likewise. * gcc.dg/pch/cpp-3b.h: Likewise. * gcc.dg/cpp/mi8.c: New test. * gcc.dg/cpp/mi8a.h: New file. * gcc.dg/cpp/mi8b.h: New file. * gcc.dg/cpp/mi8c.h: New file. * gcc.dg/cpp/mi8d.h: New file. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@138432 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/testsuite/ChangeLog10
-rw-r--r--gcc/testsuite/gcc.dg/cpp/mi8.c8
-rw-r--r--gcc/testsuite/gcc.dg/cpp/mi8a.h1
-rw-r--r--gcc/testsuite/gcc.dg/cpp/mi8b.h4
-rw-r--r--gcc/testsuite/gcc.dg/cpp/mi8c.h4
-rw-r--r--gcc/testsuite/gcc.dg/cpp/mi8d.h1
-rw-r--r--gcc/testsuite/gcc.dg/pch/cpp-3.hs3
-rw-r--r--gcc/testsuite/gcc.dg/pch/cpp-3a.h3
-rw-r--r--gcc/testsuite/gcc.dg/pch/cpp-3b.h3
-rw-r--r--libcpp/ChangeLog10
-rw-r--r--libcpp/files.c55
11 files changed, 91 insertions, 11 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 0d2ebbf6a7f..f68def01b53 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,15 @@
2008-07-31 Jakub Jelinek <jakub@redhat.com>
+ PR preprocessor/36649
+ * gcc.dg/pch/cpp-3.hs: Add include guards.
+ * gcc.dg/pch/cpp-3a.h: Likewise.
+ * gcc.dg/pch/cpp-3b.h: Likewise.
+ * gcc.dg/cpp/mi8.c: New test.
+ * gcc.dg/cpp/mi8a.h: New file.
+ * gcc.dg/cpp/mi8b.h: New file.
+ * gcc.dg/cpp/mi8c.h: New file.
+ * gcc.dg/cpp/mi8d.h: New file.
+
PR rtl-optimization/36419
* g++.dg/eh/async-unwind2.C: New test.
diff --git a/gcc/testsuite/gcc.dg/cpp/mi8.c b/gcc/testsuite/gcc.dg/cpp/mi8.c
new file mode 100644
index 00000000000..1999918dea4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/mi8.c
@@ -0,0 +1,8 @@
+/* Test multiple include guards suggestions. */
+
+/* { dg-do preprocess }
+ { dg-options "-H" }
+ { dg-message "mi8a\.h\n\[^\n\]*mi8c\.h\n\[^\n\]*mi8b\.h\n\[^\n\]*mi8d\.h\nMultiple include guards may be useful for:\n\[^\n\]*mi8a\.h\n\[^\n\]*mi8d\.h\n" "" { target *-*-* } 0 } */
+
+#include "mi8a.h"
+#include "mi8b.h"
diff --git a/gcc/testsuite/gcc.dg/cpp/mi8a.h b/gcc/testsuite/gcc.dg/cpp/mi8a.h
new file mode 100644
index 00000000000..893d9ff13b4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/mi8a.h
@@ -0,0 +1 @@
+#include "mi8c.h"
diff --git a/gcc/testsuite/gcc.dg/cpp/mi8b.h b/gcc/testsuite/gcc.dg/cpp/mi8b.h
new file mode 100644
index 00000000000..8e3482ce74b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/mi8b.h
@@ -0,0 +1,4 @@
+#ifndef GUARDB
+#define GUARDB
+#include "mi8d.h"
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/mi8c.h b/gcc/testsuite/gcc.dg/cpp/mi8c.h
new file mode 100644
index 00000000000..08c5cab94ed
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/mi8c.h
@@ -0,0 +1,4 @@
+#ifndef GUARDC
+#define GUARDC
+/* Empty */
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/mi8d.h b/gcc/testsuite/gcc.dg/cpp/mi8d.h
new file mode 100644
index 00000000000..710cecca972
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/mi8d.h
@@ -0,0 +1 @@
+/* Empty */
diff --git a/gcc/testsuite/gcc.dg/pch/cpp-3.hs b/gcc/testsuite/gcc.dg/pch/cpp-3.hs
index 40a8c178f10..728b1afc7fb 100644
--- a/gcc/testsuite/gcc.dg/pch/cpp-3.hs
+++ b/gcc/testsuite/gcc.dg/pch/cpp-3.hs
@@ -1 +1,4 @@
+#ifndef CPP_3_H
+#define CPP_3_H
/* empty */
+#endif
diff --git a/gcc/testsuite/gcc.dg/pch/cpp-3a.h b/gcc/testsuite/gcc.dg/pch/cpp-3a.h
index 2cc9fd2f9a5..3788d11791c 100644
--- a/gcc/testsuite/gcc.dg/pch/cpp-3a.h
+++ b/gcc/testsuite/gcc.dg/pch/cpp-3a.h
@@ -1 +1,4 @@
+#ifndef CPP_3A_H
+#define CPP_3A_H
#include "cpp-3b.h"
+#endif
diff --git a/gcc/testsuite/gcc.dg/pch/cpp-3b.h b/gcc/testsuite/gcc.dg/pch/cpp-3b.h
index 40a8c178f10..5cb0e810488 100644
--- a/gcc/testsuite/gcc.dg/pch/cpp-3b.h
+++ b/gcc/testsuite/gcc.dg/pch/cpp-3b.h
@@ -1 +1,4 @@
+#ifndef CPP_3B_H
+#define CPP_3B_H
/* empty */
+#endif
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index cb1de791edc..49efadc94c6 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,13 @@
+2008-07-31 Jakub Jelinek <jakub@redhat.com>
+
+ PR preprocessor/36649
+ * files.c (struct report_missing_guard_data): New type.
+ (report_missing_guard): Put paths into an array instead of printing
+ them right away. Return 1 rather than 0.
+ (report_missing_guard_cmp): New function.
+ (_cpp_report_missing_guards): Sort and print paths gathered by
+ report_missing_guard callback.
+
2008-07-22 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR 28079
diff --git a/libcpp/files.c b/libcpp/files.c
index 1adc58d88a8..007fce77d53 100644
--- a/libcpp/files.c
+++ b/libcpp/files.c
@@ -1221,12 +1221,19 @@ cpp_change_file (cpp_reader *pfile, enum lc_reason reason,
_cpp_do_file_change (pfile, reason, new_name, 1, 0);
}
+struct report_missing_guard_data
+{
+ const char **paths;
+ size_t count;
+};
+
/* Callback function for htab_traverse. */
static int
-report_missing_guard (void **slot, void *b)
+report_missing_guard (void **slot, void *d)
{
struct file_hash_entry *entry = (struct file_hash_entry *) *slot;
- int *bannerp = (int *) b;
+ struct report_missing_guard_data *data
+ = (struct report_missing_guard_data *) d;
/* Skip directories. */
if (entry->start_dir != NULL)
@@ -1236,19 +1243,25 @@ report_missing_guard (void **slot, void *b)
/* We don't want MI guard advice for the main file. */
if (file->cmacro == NULL && file->stack_count == 1 && !file->main_file)
{
- if (*bannerp == 0)
+ if (data->paths == NULL)
{
- fputs (_("Multiple include guards may be useful for:\n"),
- stderr);
- *bannerp = 1;
+ data->paths = XCNEWVEC (const char *, data->count);
+ data->count = 0;
}
- fputs (entry->u.file->path, stderr);
- putc ('\n', stderr);
+ data->paths[data->count++] = file->path;
}
}
- return 0;
+ /* Keep traversing the hash table. */
+ return 1;
+}
+
+/* Comparison function for qsort. */
+static int
+report_missing_guard_cmp (const void *p1, const void *p2)
+{
+ return strcmp (*(const char *const *) p1, *(const char *const *) p2);
}
/* Report on all files that might benefit from a multiple include guard.
@@ -1256,9 +1269,29 @@ report_missing_guard (void **slot, void *b)
void
_cpp_report_missing_guards (cpp_reader *pfile)
{
- int banner = 0;
+ struct report_missing_guard_data data;
+
+ data.paths = NULL;
+ data.count = htab_elements (pfile->file_hash);
+ htab_traverse (pfile->file_hash, report_missing_guard, &data);
- htab_traverse (pfile->file_hash, report_missing_guard, &banner);
+ if (data.paths != NULL)
+ {
+ size_t i;
+
+ /* Sort the paths to avoid outputting them in hash table
+ order. */
+ qsort (data.paths, data.count, sizeof (const char *),
+ report_missing_guard_cmp);
+ fputs (_("Multiple include guards may be useful for:\n"),
+ stderr);
+ for (i = 0; i < data.count; i++)
+ {
+ fputs (data.paths[i], stderr);
+ putc ('\n', stderr);
+ }
+ free (data.paths);
+ }
}
/* Locate HEADER, and determine whether it is newer than the current