From: Mikhail Maltsev <maltsevm@gmail.com>
To: gcc-patches mailing list <gcc-patches@gcc.gnu.org>,
Jeff Law <law@redhat.com>,
Richard Biener <richard.guenther@gmail.com>
Subject: Re: [PATCH 2/9] ENABLE_CHECKING refactoring: libcpp
Date: Mon, 05 Oct 2015 23:29:00 -0000 [thread overview]
Message-ID: <561307B6.7000707@gmail.com> (raw)
In-Reply-To: <56130763.4070206@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 415 bytes --]
libcpp/ChangeLog:
2015-10-05 Mikhail Maltsev <maltsevm@gmail.com>
* include/line-map.h: Fix use of ENABLE_CHECKING.
* init.c: Likewise.
* macro.c (struct macro_arg_token_iter, set_arg_token,
macro_arg_token_iter_init, macro_arg_token_iter_forward,
macro_arg_token_iter_get_token, macro_arg_token_iter_get_location,
alloc_expanded_arg_mem, _cpp_backup_tokens): Likewise.
* system.h (gcc_assert): Define.
[-- Attachment #2: 0002-libcpp.patch --]
[-- Type: text/x-patch, Size: 5723 bytes --]
From e7e3856c2c748cf0c7ed35ed843ec4ce516c9b4f Mon Sep 17 00:00:00 2001
From: Mikhail Maltsev <maltsevm@gmail.com>
Date: Tue, 22 Sep 2015 02:51:31 +0300
Subject: [PATCH 2/9] libcpp
---
libcpp/include/line-map.h | 2 +-
libcpp/init.c | 2 +-
libcpp/macro.c | 38 +++++++++++++++-----------------------
libcpp/system.h | 17 +++++++++++++++++
4 files changed, 34 insertions(+), 25 deletions(-)
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index bc747c1..e718fc2 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -272,7 +272,7 @@ struct GTY((tag ("2"))) line_map_macro : public line_map {
source_location expansion;
};
-#if defined ENABLE_CHECKING && (GCC_VERSION >= 2007)
+#if CHECKING_P && (GCC_VERSION >= 2007)
/* Assertion macro to be used in line-map code. */
#define linemap_assert(EXPR) \
diff --git a/libcpp/init.c b/libcpp/init.c
index 2d5626f..0419e95 100644
--- a/libcpp/init.c
+++ b/libcpp/init.c
@@ -535,7 +535,7 @@ cpp_init_builtins (cpp_reader *pfile, int hosted)
/* Sanity-checks are dependent on command-line options, so it is
called as a subroutine of cpp_read_main_file (). */
-#if ENABLE_CHECKING
+#if CHECKING_P
static void sanity_checks (cpp_reader *);
static void sanity_checks (cpp_reader *pfile)
{
diff --git a/libcpp/macro.c b/libcpp/macro.c
index 786c21b..60a0753 100644
--- a/libcpp/macro.c
+++ b/libcpp/macro.c
@@ -73,7 +73,7 @@ struct macro_arg_token_iter
-ftrack-macro-expansion is used this location tracks loci across
macro expansion. */
const source_location *location_ptr;
-#ifdef ENABLE_CHECKING
+#if CHECKING_P
/* The number of times the iterator went forward. This useful only
when checking is enabled. */
size_t num_forwards;
@@ -1310,14 +1310,11 @@ set_arg_token (macro_arg *arg, const cpp_token *token,
if (loc != NULL)
{
-#ifdef ENABLE_CHECKING
- if (kind == MACRO_ARG_TOKEN_STRINGIFIED
- || !track_macro_exp_p)
- /* We can't set the location of a stringified argument
- token and we can't set any location if we aren't tracking
- macro expansion locations. */
- abort ();
-#endif
+ /* We can't set the location of a stringified argument
+ token and we can't set any location if we aren't tracking
+ macro expansion locations. */
+ gcc_checking_assert (kind != MACRO_ARG_TOKEN_STRINGIFIED
+ && track_macro_exp_p);
*loc = location;
}
}
@@ -1403,7 +1400,7 @@ macro_arg_token_iter_init (macro_arg_token_iter *iter,
iter->location_ptr = NULL;
if (track_macro_exp_p)
iter->location_ptr = get_arg_token_location (arg, kind);
-#ifdef ENABLE_CHECKING
+#if CHECKING_P
iter->num_forwards = 0;
if (track_macro_exp_p
&& token_ptr != NULL
@@ -1428,14 +1425,14 @@ macro_arg_token_iter_forward (macro_arg_token_iter *it)
it->location_ptr++;
break;
case MACRO_ARG_TOKEN_STRINGIFIED:
-#ifdef ENABLE_CHECKING
+#if CHECKING_P
if (it->num_forwards > 0)
abort ();
#endif
break;
}
-#ifdef ENABLE_CHECKING
+#if CHECKING_P
it->num_forwards++;
#endif
}
@@ -1444,7 +1441,7 @@ macro_arg_token_iter_forward (macro_arg_token_iter *it)
static const cpp_token *
macro_arg_token_iter_get_token (const macro_arg_token_iter *it)
{
-#ifdef ENABLE_CHECKING
+#if CHECKING_P
if (it->kind == MACRO_ARG_TOKEN_STRINGIFIED
&& it->num_forwards > 0)
abort ();
@@ -1458,7 +1455,7 @@ macro_arg_token_iter_get_token (const macro_arg_token_iter *it)
static source_location
macro_arg_token_iter_get_location (const macro_arg_token_iter *it)
{
-#ifdef ENABLE_CHECKING
+#if CHECKING_P
if (it->kind == MACRO_ARG_TOKEN_STRINGIFIED
&& it->num_forwards > 0)
abort ();
@@ -2144,11 +2141,9 @@ tokens_buff_add_token (_cpp_buff *buffer,
static void
alloc_expanded_arg_mem (cpp_reader *pfile, macro_arg *arg, size_t capacity)
{
-#ifdef ENABLE_CHECKING
- if (arg->expanded != NULL
- || arg->expanded_virt_locs != NULL)
- abort ();
-#endif
+ gcc_checking_assert (arg->expanded == NULL
+ && arg->expanded_virt_locs == NULL);
+
arg->expanded = XNEWVEC (const cpp_token *, capacity);
if (CPP_OPTION (pfile, track_macro_expansion))
arg->expanded_virt_locs = XNEWVEC (source_location, capacity);
@@ -2709,10 +2704,7 @@ _cpp_backup_tokens (cpp_reader *pfile, unsigned int count)
{
macro_context *m = pfile->context->c.mc;
m->cur_virt_loc--;
-#ifdef ENABLE_CHECKING
- if (m->cur_virt_loc < m->virt_locs)
- abort ();
-#endif
+ gcc_checking_assert (m->cur_virt_loc >= m->virt_locs);
}
else
abort ();
diff --git a/libcpp/system.h b/libcpp/system.h
index e070bc9..aa336b4 100644
--- a/libcpp/system.h
+++ b/libcpp/system.h
@@ -391,6 +391,23 @@ extern void abort (void);
#define __builtin_expect(a, b) (a)
#endif
+/* Redefine abort to report an internal error w/o coredump, and
+ reporting the location of the error in the source file. */
+extern void fancy_abort (const char *, int, const char *) ATTRIBUTE_NORETURN;
+#define abort() fancy_abort (__FILE__, __LINE__, __FUNCTION__)
+
+/* Use gcc_assert(EXPR) to test invariants. */
+#if ENABLE_ASSERT_CHECKING
+#define gcc_assert(EXPR) \
+ ((void)(!(EXPR) ? fancy_abort (__FILE__, __LINE__, __FUNCTION__), 0 : 0))
+#elif (GCC_VERSION >= 4005)
+#define gcc_assert(EXPR) \
+ ((void)(__builtin_expect (!(EXPR), 0) ? __builtin_unreachable (), 0 : 0))
+#else
+/* Include EXPR, so that unused variable warnings do not occur. */
+#define gcc_assert(EXPR) ((void)(0 && (EXPR)))
+#endif
+
#ifdef ENABLE_CHECKING
#define gcc_checking_assert(EXPR) gcc_assert (EXPR)
#define CHECKING_P 1
--
2.1.4
next prev parent reply other threads:[~2015-10-05 23:29 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-05 23:27 [PATCH 1/9] ENABLE_CHECKING refactoring Mikhail Maltsev
2015-10-05 23:29 ` Mikhail Maltsev [this message]
2015-10-06 12:40 ` [PATCH 2/9] ENABLE_CHECKING refactoring: libcpp Bernd Schmidt
2015-10-12 20:57 ` Jeff Law
2015-10-19 1:18 ` Mikhail Maltsev
2015-10-21 22:29 ` Jeff Law
2015-10-21 21:19 ` Jeff Law
2015-10-05 23:30 ` [PATCH 3/9] ENABLE_CHECKING refactoring: Java and Ada Mikhail Maltsev
2015-10-22 19:25 ` Jeff Law
2015-10-05 23:31 ` [PATCH 4/9] ENABLE_CHECKING refactoring: Fortran Mikhail Maltsev
2015-10-23 22:38 ` Jeff Law
2015-10-05 23:32 ` [PATCH 5/9] ENABLE_CHECKING refactoring: pool allocators Mikhail Maltsev
2015-10-06 12:41 ` Bernd Schmidt
2015-10-06 12:45 ` Richard Biener
2015-10-19 0:47 ` Mikhail Maltsev
2015-10-21 11:02 ` Richard Biener
2015-10-26 2:07 ` Mikhail Maltsev
2015-10-26 9:48 ` Richard Biener
2015-10-26 10:57 ` Mikhail Maltsev
2015-10-05 23:34 ` [PATCH 6/9] ENABLE_CHECKING refactoring: generators Mikhail Maltsev
2015-10-06 12:57 ` Richard Biener
2015-10-19 0:09 ` Mikhail Maltsev
2015-10-21 10:57 ` Richard Biener
2015-10-28 16:32 ` Jeff Law
2015-10-29 16:31 ` Jeff Law
2015-10-05 23:39 ` [PATCH 7/9] ENABLE_CHECKING refactoring: middle-end, LTO FE Mikhail Maltsev
2015-10-06 12:46 ` Bernd Schmidt
2015-10-06 12:59 ` Richard Biener
2015-10-06 12:59 ` Richard Biener
2015-10-19 0:56 ` Mikhail Maltsev
2015-10-19 12:19 ` Bernd Schmidt
2015-10-26 17:04 ` Jeff Law
2015-10-26 17:15 ` Bernd Schmidt
2015-10-26 19:05 ` Jeff Law
2015-10-28 1:17 ` Jeff Law
2015-10-28 2:12 ` Trevor Saunders
2015-10-05 23:40 ` [PATCH 8/9] ENABLE_CHECKING refactoring: target-specific parts Mikhail Maltsev
2015-10-06 12:48 ` Bernd Schmidt
2015-10-29 19:43 ` Jeff Law
2015-10-29 21:23 ` Jeff Law
2015-10-30 4:13 ` Jeff Law
2015-10-30 4:20 ` Jeff Law
2015-10-06 12:53 ` [PATCH 1/9] ENABLE_CHECKING refactoring Richard Biener
2015-10-12 20:48 ` Jeff Law
2015-10-13 21:33 ` Jeff Law
2015-10-18 8:25 ` Mikhail Maltsev
2015-10-19 11:14 ` Bernd Schmidt
2015-10-19 13:54 ` Mikhail Maltsev
2015-10-21 15:59 ` Jeff Law
2015-10-21 16:06 ` Bernd Schmidt
2015-10-21 16:18 ` Richard Biener
2015-10-21 16:28 ` Jeff Law
2015-11-07 22:42 ` Gerald Pfeifer
2015-10-21 16:19 ` Jeff Law
2015-10-21 16:22 ` Bernd Schmidt
2015-10-21 16:44 ` Jakub Jelinek
2015-10-22 7:58 ` Richard Biener
2015-10-21 20:06 ` Jeff Law
2015-10-20 16:14 ` Jeff Law
2015-10-21 21:17 ` Jeff Law
2015-11-01 14:58 ` [PATCH 9/9] ENABLE_CHECKING refactoring: C family front ends Mikhail Maltsev
2015-11-02 23:34 ` Jeff Law
2015-11-04 14:41 ` Mikhail Maltsev
2015-11-01 20:19 ` [PATCH 10/9] ENABLE_CHECKING refactoring: remove remaining occurrences Mikhail Maltsev
2015-11-02 23:35 ` Jeff Law
2015-11-04 15:03 ` Mikhail Maltsev
2016-02-23 15:21 ` Richard Biener
2016-02-24 14:17 ` Martin Liška
2016-02-24 14:27 ` Michael Matz
2016-02-24 14:53 ` Martin Liška
2016-02-24 15:43 ` Pierre-Marie de Rodat
2016-02-25 9:24 ` Richard Biener
2016-02-25 10:14 ` Pierre-Marie de Rodat
2016-02-25 10:15 ` Martin Liška
2016-02-25 10:16 ` Pierre-Marie de Rodat
2016-02-25 9:24 ` Richard Biener
[not found] ` <C5BB0125-FB5F-46C6-B16D-74C3D0F07C10@gmail.com>
2015-11-08 15:37 ` Mikhail Maltsev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=561307B6.7000707@gmail.com \
--to=maltsevm@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=law@redhat.com \
--cc=richard.guenther@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).