From patchwork Wed Apr 5 01:14:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9662815 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 489496021C for ; Wed, 5 Apr 2017 01:17:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 388DB23B24 for ; Wed, 5 Apr 2017 01:17:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D8FE2711E; Wed, 5 Apr 2017 01:17:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C74DF23B24 for ; Wed, 5 Apr 2017 01:17:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751396AbdDEBRI (ORCPT ); Tue, 4 Apr 2017 21:17:08 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:35495 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754758AbdDEBRG (ORCPT ); Tue, 4 Apr 2017 21:17:06 -0400 Received: by mail-wm0-f67.google.com with SMTP id z133so185780wmb.2 for ; Tue, 04 Apr 2017 18:17:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nbLbn2csSQ79RpzRT+r7ddtbHy5BOS6hobAOtWnjM1I=; b=LAXWbh1YhwNGMrnKhres/pRyuIFQMeTlaUTBa0s16+HrgJqufe9x0agu0HUrZIb5MO cKiqTVg1zjUp63cKuYj+FVVd8HClisXvcbrY1A9SlrqVvxVmaaaEDkCVl7YuPAE8KzTk oMx9oQ+GFJa9DFSmmE12VOUeeTi4SmvJb69Cj5AOCTeDTOYFaEFENz1PN2tLZ3UNHHVu ZKu0IXCXpPDj12AA/bC4uMNEVpHY1Y2VPxgtAkLD02SdZQJ8l6eCejhF8mdKQbtgtCDE jPD1gRRAcKWI7rwbBF8X5V8nkKw7+vUppsrICa+2GsG4RpD+Uy8FVsNkU85tbXEj5xym HeyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nbLbn2csSQ79RpzRT+r7ddtbHy5BOS6hobAOtWnjM1I=; b=tMPdJlvf4CTNhs/uE96+BdOYL+YhKSU7LiGdJxzXhcJq0c34MGPq6DoFQUx9+EAgs5 x4ultrgJGOoMdduMnYmKLm8NXaeX1WHKelTj5jPme84viWYoTuDuLethuU0VrZQwB6D1 aSXv4k7W25tjooBH4WPXzPrGU3yXEhGK3Vnga/KqlmxPh8z9iMPwx9zA8jcOadbPp5XX Nu8dYMCDti3CKR6Du+KDVtO8clJhZecu+ZPOYfP+Pg2DPWKzXB2nxynYth0m9ixWMl8o hmBsA7jGzlsWQvdaqbtPqZitIMKBzWPQ84k1tsMP4Cou8RR/mmBrmotatS8NgJDywEE5 73lw== X-Gm-Message-State: AFeK/H0uuzL+j1DXajRfws9G2Xhd+i3m1oD4188r1rJiEDdRTLNbRTvU etH6yo398SbPpQ== X-Received: by 10.28.225.69 with SMTP id y66mr17488677wmg.84.1491355025482; Tue, 04 Apr 2017 18:17:05 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:88d:1900:706c:6cb1:d133:7ca3]) by smtp.gmail.com with ESMTPSA id b82sm20310668wmh.4.2017.04.04.18.17.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Apr 2017 18:17:04 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Luc Van Oostenryck Subject: [PATCH 3/3] add real support for __BASE_FILE__ Date: Wed, 5 Apr 2017 03:14:55 +0200 Message-Id: <20170405011455.60222-4-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170405011455.60222-1-luc.vanoostenryck@gmail.com> References: <20170405011455.60222-1-luc.vanoostenryck@gmail.com> Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There was some support of it but it was probably just for sparse to not complain as it was a define that expanded to the fixed name "base_file.c". Fix this by letting it expand to the basename of the input file. Signed-off-by: Luc Van Oostenryck --- ident-list.h | 1 + lib.c | 3 --- pre-process.c | 4 ++++ validation/preprocessor/__BASE_FILE__.c | 11 +++++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 validation/preprocessor/__BASE_FILE__.c diff --git a/ident-list.h b/ident-list.h index 8cc66a50c..21564bc5b 100644 --- a/ident-list.h +++ b/ident-list.h @@ -104,6 +104,7 @@ __IDENT(pragma_ident, "__pragma__", 0); __IDENT(__VA_ARGS___ident, "__VA_ARGS__", 0); __IDENT(__LINE___ident, "__LINE__", 0); __IDENT(__FILE___ident, "__FILE__", 0); +__IDENT(__BASE_FILE___ident, "__BASE_FILE__", 0); __IDENT(__DATE___ident, "__DATE__", 0); __IDENT(__TIME___ident, "__TIME__", 0); __IDENT(__func___ident, "__func__", 0); diff --git a/lib.c b/lib.c index 272d2c88a..0b4564f5a 100644 --- a/lib.c +++ b/lib.c @@ -1038,9 +1038,6 @@ void create_builtin_stream(void) add_pre_buffer("#define __builtin_ms_va_end(arg)\n"); add_pre_buffer("#define __builtin_va_arg_pack()\n"); - /* FIXME! We need to do these as special magic macros at expansion time! */ - add_pre_buffer("#define __BASE_FILE__ \"base_file.c\"\n"); - if (optimize) add_pre_buffer("#define __OPTIMIZE__ 1\n"); if (optimize_size) diff --git a/pre-process.c b/pre-process.c index 7c57ba1cd..dd698c5bc 100644 --- a/pre-process.c +++ b/pre-process.c @@ -172,6 +172,10 @@ static int expand_one_symbol(struct token **list) replace_with_integer(token, token->pos.line); } else if (token->ident == &__FILE___ident) { replace_with_string(token, stream_name(token->pos.stream)); + } else if (token->ident == &__BASE_FILE___ident) { + const char *base = stream_name(token->pos.stream); + base = sparse_basename(base); + replace_with_string(token, base); } else if (token->ident == &__DATE___ident) { if (!t) time(&t); diff --git a/validation/preprocessor/__BASE_FILE__.c b/validation/preprocessor/__BASE_FILE__.c new file mode 100644 index 000000000..d1cce9633 --- /dev/null +++ b/validation/preprocessor/__BASE_FILE__.c @@ -0,0 +1,11 @@ +__BASE_FILE__ + +/* + * check-name: __BASE_FILE__ + * check-command: sparse -E $file + * + * check-output-start + +"__BASE_FILE__.c" + * check-output-end + */