From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 99775 invoked by alias); 4 Aug 2017 21:30:53 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 99493 invoked by uid 89); 4 Aug 2017 21:30:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 04 Aug 2017 21:30:21 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D5BFE769E9 for ; Fri, 4 Aug 2017 21:30:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D5BFE769E9 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=dmalcolm@redhat.com Received: from c64.redhat.com (ovpn-112-14.phx2.redhat.com [10.3.112.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFAFC61F20; Fri, 4 Aug 2017 21:30:08 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 01/22] Expose assert_loceq outside of input.c; add ASSERT_LOCEQ Date: Fri, 04 Aug 2017 21:30:00 -0000 Message-Id: <1501884293-9047-2-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1501884293-9047-1-git-send-email-dmalcolm@redhat.com> References: <1501884293-9047-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes X-SW-Source: 2017-08/txt/msg00415.txt.bz2 gcc/ChangeLog: * input.c: Include "selftest-input.h". (selftest::assert_loceq): Remove "static". Add "report_loc" param and update assertions to use it. (selftest::test_accessing_ordinary_linemaps): Use ASSERT_LOCEQ rather than assert_loceq. (selftest::test_builtins): Likewise. * selftest-input.h: New file. --- gcc/input.c | 39 +++++++++++++++++++------------------ gcc/selftest-input.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 18 deletions(-) create mode 100644 gcc/selftest-input.h diff --git a/gcc/input.c b/gcc/input.c index 0480eb2..1aad551 100644 --- a/gcc/input.c +++ b/gcc/input.c @@ -23,6 +23,7 @@ along with GCC; see the file COPYING3. If not see #include "intl.h" #include "diagnostic-core.h" #include "selftest.h" +#include "selftest-input.h" #include "cpplib.h" #ifndef HAVE_ICONV @@ -1613,21 +1614,23 @@ test_should_have_column_data_p () } /* Verify the result of LOCATION_FILE/LOCATION_LINE/LOCATION_COLUMN - on LOC. */ + on LOC. Use REPORT_LOC as the effective location when reporting + any issues. */ -static void -assert_loceq (const char *exp_filename, int exp_linenum, int exp_colnum, +void +assert_loceq (const location &report_loc, + const char *exp_filename, int exp_linenum, int exp_colnum, location_t loc) { - ASSERT_STREQ (exp_filename, LOCATION_FILE (loc)); - ASSERT_EQ (exp_linenum, LOCATION_LINE (loc)); + ASSERT_STREQ_AT (report_loc, exp_filename, LOCATION_FILE (loc)); + ASSERT_EQ_AT (report_loc, exp_linenum, LOCATION_LINE (loc)); /* If location_t values are sufficiently high, then column numbers will be unavailable and LOCATION_COLUMN (loc) will be 0. When close to the threshold, column numbers *may* be present: if the final linemap before the threshold contains a line that straddles the threshold, locations in that line have column information. */ if (should_have_column_data_p (loc)) - ASSERT_EQ (exp_colnum, LOCATION_COLUMN (loc)); + ASSERT_EQ_AT (report_loc, exp_colnum, LOCATION_COLUMN (loc)); } /* Various selftests involve constructing a line table and one or more @@ -1761,23 +1764,23 @@ test_accessing_ordinary_linemaps (const line_table_case &case_) linemap_add (line_table, LC_LEAVE, false, NULL, 0); /* Verify that we can recover the location info. */ - assert_loceq ("foo.c", 1, 1, loc_a); - assert_loceq ("foo.c", 1, 23, loc_b); - assert_loceq ("foo.c", 2, 1, loc_c); - assert_loceq ("foo.c", 2, 17, loc_d); - assert_loceq ("foo.c", 3, 700, loc_e); - assert_loceq ("foo.c", 4, 100, loc_back_to_short); + ASSERT_LOCEQ ("foo.c", 1, 1, loc_a); + ASSERT_LOCEQ ("foo.c", 1, 23, loc_b); + ASSERT_LOCEQ ("foo.c", 2, 1, loc_c); + ASSERT_LOCEQ ("foo.c", 2, 17, loc_d); + ASSERT_LOCEQ ("foo.c", 3, 700, loc_e); + ASSERT_LOCEQ ("foo.c", 4, 100, loc_back_to_short); /* In the very wide line, the initial location should be fully tracked. */ - assert_loceq ("foo.c", 5, 2000, loc_start_of_very_long_line); + ASSERT_LOCEQ ("foo.c", 5, 2000, loc_start_of_very_long_line); /* ...but once we exceed LINE_MAP_MAX_COLUMN_NUMBER column-tracking should be disabled. */ - assert_loceq ("foo.c", 5, 0, loc_too_wide); - assert_loceq ("foo.c", 5, 0, loc_too_wide_2); + ASSERT_LOCEQ ("foo.c", 5, 0, loc_too_wide); + ASSERT_LOCEQ ("foo.c", 5, 0, loc_too_wide_2); /*...and column-tracking should be re-enabled for subsequent lines. */ - assert_loceq ("foo.c", 6, 10, loc_sane_again); + ASSERT_LOCEQ ("foo.c", 6, 10, loc_sane_again); - assert_loceq ("bar.c", 1, 150, loc_f); + ASSERT_LOCEQ ("bar.c", 1, 150, loc_f); ASSERT_FALSE (is_location_from_builtin_token (loc_a)); ASSERT_TRUE (pure_location_p (line_table, loc_a)); @@ -1807,7 +1810,7 @@ test_unknown_location () static void test_builtins () { - assert_loceq (_(""), 0, 0, BUILTINS_LOCATION); + ASSERT_LOCEQ (_(""), 0, 0, BUILTINS_LOCATION); ASSERT_PRED1 (is_location_from_builtin_token, BUILTINS_LOCATION); } diff --git a/gcc/selftest-input.h b/gcc/selftest-input.h new file mode 100644 index 0000000..d56af36 --- /dev/null +++ b/gcc/selftest-input.h @@ -0,0 +1,54 @@ +/* Support for selftests of location handling. + Copyright (C) 2016-2017 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#ifndef GCC_SELFTEST_INPUT_H +#define GCC_SELFTEST_INPUT_H + +/* The selftest code should entirely disappear in a production + configuration, hence we guard all of it with #if CHECKING_P. */ + +#if CHECKING_P + +namespace selftest { + +/* input.c. */ + +/* Verify the result of LOCATION_FILE/LOCATION_LINE/LOCATION_COLUMN + on LOC. Use REPORT_LOC as the effective location when reporting + any issues. */ + +extern void assert_loceq (const location &report_loc, + const char *exp_filename, int exp_linenum, + int exp_colnum, location_t loc); + +/* Evaluate EXP_FILENAME, EXP_LINENUM, EXP_COLNUM, and LOC. + Verify the result of LOCATION_FILE/LOCATION_LINE/LOCATION_COLUMN + on LOC. */ + +#define ASSERT_LOCEQ(EXP_FILENAME, EXP_LINENUM, EXP_COLNUM, LOC) \ + SELFTEST_BEGIN_STMT \ + ::selftest::assert_loceq (SELFTEST_LOCATION, (EXP_FILENAME), \ + (EXP_LINENUM), (EXP_COLNUM), (LOC)); \ + SELFTEST_END_STMT + +} /* end of namespace selftest. */ + +#endif /* #if CHECKING_P */ + +#endif /* GCC_SELFTEST_INPUT_H */ -- 1.8.5.3