From patchwork Sun Jul 5 13:02:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11644373 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1825192A for ; Sun, 5 Jul 2020 13:02:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 00A632070B for ; Sun, 5 Jul 2020 13:02:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="B148VQCZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726903AbgGENCa (ORCPT ); Sun, 5 Jul 2020 09:02:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726792AbgGENCa (ORCPT ); Sun, 5 Jul 2020 09:02:30 -0400 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03DA9C08C5DE for ; Sun, 5 Jul 2020 06:02:30 -0700 (PDT) Received: by mail-ed1-x542.google.com with SMTP id z17so32200812edr.9 for ; Sun, 05 Jul 2020 06:02:29 -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 :mime-version:content-transfer-encoding; bh=DbS74vQpmV1GX6dYv3vTq6zgY9FWesbjUccvShGMrLU=; b=B148VQCZmnZ47ylRFDEg9yfxB+dWa8gn1dmaN5J7+RfgX3uK/6CKsXLK6mHabRsVRf pAxGlyRSA/QMESADkzUk4CwRRfyiyQ2H/gPTIxu4rmJJe0y213N6gP5InUY/K2cFSvB9 JSfd5N4N/BsObhv7MivDMSxZP25psO4D7IGCgZet1t8ZoB7qdiXUwr9sRd+H1DfCrAIP go15adJ3TFsKpcNcmHAYnf7RQ/VCKiQcpBI+1Co1it3267xXso4kvZOw3a7hv4fgAr+a cDUzx/y0YJ2jo4Hh4lDG3XC27xuVNZoigC8FCxc7sJDfULkB47M7VLxTdQCgNTJg+SMP L7Tw== 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:mime-version:content-transfer-encoding; bh=DbS74vQpmV1GX6dYv3vTq6zgY9FWesbjUccvShGMrLU=; b=he/lLIfPQvKOf2DgOICbRk2o1fG6eKnNBPrKGZNSBzStdXjmdlS2HfC7bQixYQIx3T qbfquNj1oH5yTm9pnJY1AajIFUcXLuKgNkOgWQlya0J/vllbH5n9XwabuXDKzcH5j3Xo ARnBTBZl9udfvViq9WtZnAVJPAaI7Mt11VzifzIHFfidxxJIkYGA1l2rDN+IM2JwLXbZ gGEaTkTWZL0xhaJQCG131iiA5UudBQRfIVOg0KgypJRNr9Flss/2uLTnbx6DJ71Dt6Qb uUNbfGhpIKvOZhOXV2U8kL2kWKr7npx36WBVToeMorNTWTNp6nxsGBB9Ceus877f9llp m+bw== X-Gm-Message-State: AOAM532p1VWJMRm8GeMBvIvKP6NR3GKvuJLANORvVjbUeRaiKSTnsDGf AO5iiKJRfEwwmojz89Ol5BJUb/J6 X-Google-Smtp-Source: ABdhPJzZSxlegVXupAnPBrDyWP5XIMBwtiutzEhZfiKtLeiFSwy2OdJQhlDSgU5ET12Frkf8kwObvw== X-Received: by 2002:a50:dacf:: with SMTP id s15mr52580116edj.136.1593954148510; Sun, 05 Jul 2020 06:02:28 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7f9:7600:a542:d3fb:b75a:dec5]) by smtp.gmail.com with ESMTPSA id x16sm19535945edr.52.2020.07.05.06.02.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jul 2020 06:02:28 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 01/15] options: let handle_onoff_switch() use null terminated arrays Date: Sun, 5 Jul 2020 15:02:06 +0200 Message-Id: <20200705130220.26230-2-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> References: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org This makes things slightly easier to use. Signed-off-by: Luc Van Oostenryck --- lib.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib.c b/lib.c index e56788260cb7..709dd5176112 100644 --- a/lib.c +++ b/lib.c @@ -529,14 +529,14 @@ enum { WARNING_FORCE_OFF }; -static char **handle_onoff_switch(char *arg, char **next, const struct flag warnings[], int n) +static char **handle_onoff_switch(char *arg, char **next, const struct flag warnings[]) { int flag = WARNING_ON; char *p = arg + 1; unsigned i; if (!strcmp(p, "sparse-all")) { - for (i = 0; i < n; i++) { + for (i = 0; warnings[i].name; i++) { if (*warnings[i].flag != WARNING_FORCE_OFF && warnings[i].flag != &Wsparse_error) *warnings[i].flag = WARNING_ON; } @@ -551,7 +551,7 @@ static char **handle_onoff_switch(char *arg, char **next, const struct flag warn flag = WARNING_FORCE_OFF; } - for (i = 0; i < n; i++) { + for (i = 0; warnings[i].name; i++) { if (!strcmp(p,warnings[i].name)) { *warnings[i].flag = flag; return next; @@ -789,11 +789,12 @@ static const struct flag warnings[] = { { "universal-initializer", &Wuniversal_initializer }, { "unknown-attribute", &Wunknown_attribute }, { "vla", &Wvla }, + { } }; static char **handle_switch_W(char *arg, char **next) { - char ** ret = handle_onoff_switch(arg, next, warnings, ARRAY_SIZE(warnings)); + char ** ret = handle_onoff_switch(arg, next, warnings); if (ret) return ret; @@ -808,12 +809,13 @@ static struct flag debugs[] = { { "entry", &dbg_entry}, { "ir", &dbg_ir}, { "postorder", &dbg_postorder}, + { } }; static char **handle_switch_v(char *arg, char **next) { - char ** ret = handle_onoff_switch(arg, next, debugs, ARRAY_SIZE(debugs)); + char ** ret = handle_onoff_switch(arg, next, debugs); if (ret) return ret; @@ -856,11 +858,11 @@ static char **handle_switch_d(char *arg, char **next) } -static void handle_onoff_switch_finalize(const struct flag warnings[], int n) +static void handle_onoff_switch_finalize(const struct flag warnings[]) { unsigned i; - for (i = 0; i < n; i++) { + for (i = 0; warnings[i].name; i++) { if (*warnings[i].flag == WARNING_FORCE_OFF) *warnings[i].flag = WARNING_OFF; } @@ -868,7 +870,7 @@ static void handle_onoff_switch_finalize(const struct flag warnings[], int n) static void handle_switch_W_finalize(void) { - handle_onoff_switch_finalize(warnings, ARRAY_SIZE(warnings)); + handle_onoff_switch_finalize(warnings); /* default Wdeclarationafterstatement based on the C dialect */ if (-1 == Wdeclarationafterstatement) { @@ -886,7 +888,7 @@ static void handle_switch_W_finalize(void) static void handle_switch_v_finalize(void) { - handle_onoff_switch_finalize(debugs, ARRAY_SIZE(debugs)); + handle_onoff_switch_finalize(debugs); } static char **handle_switch_U(char *arg, char **next) From patchwork Sun Jul 5 13:02:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11644375 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E622D92A for ; Sun, 5 Jul 2020 13:02:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CF64A20771 for ; Sun, 5 Jul 2020 13:02:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DSiYvAqJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726915AbgGENCb (ORCPT ); Sun, 5 Jul 2020 09:02:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726792AbgGENCb (ORCPT ); Sun, 5 Jul 2020 09:02:31 -0400 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1AC3C061794 for ; Sun, 5 Jul 2020 06:02:30 -0700 (PDT) Received: by mail-ed1-x542.google.com with SMTP id dm19so25930027edb.13 for ; Sun, 05 Jul 2020 06:02:30 -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 :mime-version:content-transfer-encoding; bh=cF8b+JGj0G/772jPhd4SDBLuCY+ZY7XeryhECDKmgiQ=; b=DSiYvAqJ292ffXxftZiiOxXHHDlrQZv65oOMqBKwmHJuFA9d1+l2JCi2g7Ayqhvy7Z SGe6m+UGfehLT+xxAzJCtM5yzsVqZYpUzGebT/zqUBcbniXcu+xIMgwa+6+nqn9C9KZv eNOh6sUGOgAJz9qsaR0Uth8DazhIldDI4DomokY9c455zKpPErWlXXbJbiggp2UuiKma lynj4VwfAivWt2LlRDiSVgr93TrWnz3FrFFrFmPfpekn5ilq8aC2iQPwixUaYklRL+11 du1BiI6te5uLNG/h4EMyorCTA5fIJT5+7cdwwVa/XNZBW3LFasLVQ7gjmCLL9QYxH0aM QAyQ== 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:mime-version:content-transfer-encoding; bh=cF8b+JGj0G/772jPhd4SDBLuCY+ZY7XeryhECDKmgiQ=; b=YbxIcuNi9yZXqQviG7ifUKMN06XuvNl0usmE2RfY66PedyNTFkDB/8U4e8AKuR8Uym h0SMPI8Eo1pB812it+SOs1R+ec0x/aV3isUOoiWAq5bBfXzZE9zqqgyvQvUyAcL/cJRM R1GPAuoVGdOQY4tiFm0g7mjN++/x8d/d2p52Jy5k/fdH6tHhEINUhur+rKtqtCs6xepo wrbRknghPBVD4sgcLW06QWkTEv6uXWny8l4NviHRBDPfnKtxI8K/bjjiIQgr+Qq3aGgw UcOYEVGRYRGBD+/pZ/UPK62LhZhmVYqIlLyLau2Vcsdby9D21GIHfM8Y6cQmyAvCiQOh zZIg== X-Gm-Message-State: AOAM5313SoFo0RBretG+2x9fnCi5YNRwVKHCP5evSClfeEFKQp1BibRv yPomS7A0Y9+WOu8wHEXx8JZWgJcW X-Google-Smtp-Source: ABdhPJzSpTvWgrB5s5MiFWtfIdqUbiTg8jXzVLGXFvZ4be9iWs1m/3qZS34ExGNrGUu6vHUTynxgRQ== X-Received: by 2002:a05:6402:1d18:: with SMTP id dg24mr51205905edb.33.1593954149558; Sun, 05 Jul 2020 06:02:29 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7f9:7600:a542:d3fb:b75a:dec5]) by smtp.gmail.com with ESMTPSA id x16sm19535945edr.52.2020.07.05.06.02.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jul 2020 06:02:29 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 02/15] options: move -Wsparse-all's processing out of handle_onoff_switch() Date: Sun, 5 Jul 2020 15:02:07 +0200 Message-Id: <20200705130220.26230-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> References: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Since handle_onoff_switch() can be used for other flags than the warnings, the processing of -Wsparse-all should move elsewhere. So move it into handle_switch_W(). Signed-off-by: Luc Van Oostenryck --- lib.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib.c b/lib.c index 709dd5176112..5128a5b64e9e 100644 --- a/lib.c +++ b/lib.c @@ -535,14 +535,6 @@ static char **handle_onoff_switch(char *arg, char **next, const struct flag warn char *p = arg + 1; unsigned i; - if (!strcmp(p, "sparse-all")) { - for (i = 0; warnings[i].name; i++) { - if (*warnings[i].flag != WARNING_FORCE_OFF && warnings[i].flag != &Wsparse_error) - *warnings[i].flag = WARNING_ON; - } - return NULL; - } - // Prefixes "no" and "no-" mean to turn warning off. if (p[0] == 'n' && p[1] == 'o') { p += 2; @@ -798,6 +790,14 @@ static char **handle_switch_W(char *arg, char **next) if (ret) return ret; + if (!strcmp(arg, "Wsparse-all")) { + int i; + for (i = 0; warnings[i].name; i++) { + if (*warnings[i].flag != WARNING_FORCE_OFF && warnings[i].flag != &Wsparse_error) + *warnings[i].flag = WARNING_ON; + } + } + // Unknown. return next; } From patchwork Sun Jul 5 13:02:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11644377 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0362A92A for ; Sun, 5 Jul 2020 13:02:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E0FB92075D for ; Sun, 5 Jul 2020 13:02:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Q4W6BsV9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726931AbgGENCc (ORCPT ); Sun, 5 Jul 2020 09:02:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726792AbgGENCc (ORCPT ); Sun, 5 Jul 2020 09:02:32 -0400 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8C9FC061794 for ; Sun, 5 Jul 2020 06:02:31 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id d18so26551962edv.6 for ; Sun, 05 Jul 2020 06:02:31 -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 :mime-version:content-transfer-encoding; bh=PLDxotR4LWJLM1++xc/ZIF1iQIELRIcRP3vM3vOzBKE=; b=Q4W6BsV9Doe8YG+EJmdRNr/AWYUlwA55GHAUBbFh+OZkzErbBv0EGerW5oWYswq4hh g5f94eJ1W7Y7OKrYmEtnEfqjOFZXRs/AEYCnHGh25ScXNVFIovdOgOieo5yEp3mHqXAC qRBFyHcc7DU2zOja8sI62JXHjbFGcrrJjrYYPkGURQoF4fTc3GyirbJ00Ws+oZmG8eIK fGUAyZHvcHlSUMkCvx4YNqgybbWmAWSSWiR748ntVrLeT5Y3aAt6OULyUN+G/vPee2C3 e0jjsCuTM/ieRHIRZLmpq+jamlM2VFvpQUjYPP7kuIfhtrrvyfkZBA7ve9S3umQJxLcZ EuWw== 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:mime-version:content-transfer-encoding; bh=PLDxotR4LWJLM1++xc/ZIF1iQIELRIcRP3vM3vOzBKE=; b=tp9Fh+01TK+UKUTpYDu8SRcswOtQl69ONXk9Iin6KN+si0hmlawD2D5ax9wxOOc8Sw vX4AxFPjqXpz2grDU99lucPJn1Jrls13+wNHM+3iy6JS6uejBI/2C0P4fMa8DJ0kdQRk mUB6txh9ieH67h+sxgK2xB8dg11AYPQA6E3LgUEpQH8d/z1mML14A10QbDqv9bHbCZG9 yvJ4cdP0X5w3tUDYQsd9ZQjqiAhEpO3XGAJrt8x7SM6Ynzj+Tfmfq+cnLWYChB8wnBsm Hmk++/znfsK6iR9+4aYzt0uA/Yl8OB81brjXPIEXScmeBBEkylVXfYbNPcoMEV++0D7U WnnQ== X-Gm-Message-State: AOAM531oAUVQjq1xEoTY6AxzIxLUepmyCxOy1bTbV+9rGjkxYwz/sY7K l93PMf3pFQ/Vhl6Ep05ews/3U1wt X-Google-Smtp-Source: ABdhPJylz/l0iBaQ5h4THW8GgH16WnAe5A4gkcnNi+hlepLffbsvnVIMoKpKydZv1fq3tuXwvBFv2w== X-Received: by 2002:a05:6402:b84:: with SMTP id cf4mr25796953edb.21.1593954150416; Sun, 05 Jul 2020 06:02:30 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7f9:7600:a542:d3fb:b75a:dec5]) by smtp.gmail.com with ESMTPSA id x16sm19535945edr.52.2020.07.05.06.02.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jul 2020 06:02:29 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 03/15] options: move on top the definition of warning type enums Date: Sun, 5 Jul 2020 15:02:08 +0200 Message-Id: <20200705130220.26230-4-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> References: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org This allows to reuse these enums in earlier helpers. Signed-off-by: Luc Van Oostenryck --- lib.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib.c b/lib.c index 5128a5b64e9e..43d55a0648ee 100644 --- a/lib.c +++ b/lib.c @@ -250,6 +250,12 @@ void die(const char *fmt, ...) static struct token *pre_buffer_begin = NULL; static struct token *pre_buffer_end = NULL; +enum warning_type { + WARNING_OFF, + WARNING_ON, + WARNING_FORCE_OFF +}; + int Waddress = 0; int Waddress_space = 1; int Wbitwise = 1; @@ -523,12 +529,6 @@ static int opt_##NAME(const char *arg, const char *opt, TYPE *ptr, int flag) \ OPT_NUMERIC(ullong, unsigned long long, strtoull) OPT_NUMERIC(uint, unsigned int, strtoul) -enum { - WARNING_OFF, - WARNING_ON, - WARNING_FORCE_OFF -}; - static char **handle_onoff_switch(char *arg, char **next, const struct flag warnings[]) { int flag = WARNING_ON; From patchwork Sun Jul 5 13:02:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11644379 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF73714DD for ; Sun, 5 Jul 2020 13:02:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 97F4B20747 for ; Sun, 5 Jul 2020 13:02:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Fnye3c6q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726933AbgGENCd (ORCPT ); Sun, 5 Jul 2020 09:02:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726792AbgGENCd (ORCPT ); Sun, 5 Jul 2020 09:02:33 -0400 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6A01C061794 for ; Sun, 5 Jul 2020 06:02:32 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id a8so30993232edy.1 for ; Sun, 05 Jul 2020 06:02:32 -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 :mime-version:content-transfer-encoding; bh=iQrFRXDP8rXNHQcWYNSe+JctoXgQP0kT+O7TInIWU9c=; b=Fnye3c6qFWEptJxKdM5KTBf0mpu5aHJobbgGL+lvC8Y292CFGCVKiQKyj1h2jEbMIG qQE+jfqhXZplBrXZk2QJH0obmELFDfsARhKJPvZqjoNrglX9FHNLa9CvKYL9JayMivOl wkea4ZAIrIVw7u9dlgD+dxe6mLnwJgqS49n5tyJFJHehDKLeeSG1wZvLjztR3Y3Io9PB jEmQ+fgrSA59Ao+5HSCtqB1OmaU7HfnoPSMNbsg5ysh9IgsNmxQIYYzBKiyQi47ggMjH aRF7klq+j+nNJSqlV7MgX3tf/v+QIGT2/d+20gDJkJwAIVqy4W0CVLy3pqRU0+S4Z4an 4mjQ== 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:mime-version:content-transfer-encoding; bh=iQrFRXDP8rXNHQcWYNSe+JctoXgQP0kT+O7TInIWU9c=; b=DDNsnjBtsF8s93LlDiPLD2YEIr5EZLA44iCQCVG3ePDCWgxavrl1r0w0xRP58zuggP zYjwbidHFLFrhMvnpIBR5QZkMIpKsIkaqsBt66yAA0G5y383l4Q8DgeO3VLsrRmQmajq boJ544qSFjQ17Ve82+b92zVC60SDSkJkGOm4DIhJJ+DYv0RtnbqgKow3Kf8vBBF+XaQ2 m55yUd12lyiqmZWl9LjXvmHcxkq41CKLGoZgek3iP/epVZXCP9+Dns4Sbc5377iOjwO1 HXc0pZzac/ppkLP91ABHAe0xiFO7eY7uTPhe3BjQ0FqY1URJCLorEeeeqgT4Oxe50Rar eF8Q== X-Gm-Message-State: AOAM533Ktqvhw31fngSvY0USHxgoSzFFGhRqmj7HWf2dka5vMVMadTxy M8giD3ZrZZz99VqZHFP2jBdjlk2C X-Google-Smtp-Source: ABdhPJy86BGK5Mmg9jVNBhE5M/paQxHoI8s7yFKAXoeMX7K/5wkwI1AmlOYS6Q0n4j/oU2gBrXnvSQ== X-Received: by 2002:a50:f392:: with SMTP id g18mr27960447edm.151.1593954151414; Sun, 05 Jul 2020 06:02:31 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7f9:7600:a542:d3fb:b75a:dec5]) by smtp.gmail.com with ESMTPSA id x16sm19535945edr.52.2020.07.05.06.02.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jul 2020 06:02:31 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 04/15] options: make Wsparse_error less special Date: Sun, 5 Jul 2020 15:02:09 +0200 Message-Id: <20200705130220.26230-5-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> References: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org -Wsparse-error should not be enabled with -Wsparse-all, this is special cased in the condition in loop handling -Wsparse-all. However, the condition already handle warnings forced to off. So instead of explicitly checking for &Wsparse_error, it's enough to force Wsparse_error off. Signed-off-by: Luc Van Oostenryck --- lib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib.c b/lib.c index 43d55a0648ee..9acdc60fc416 100644 --- a/lib.c +++ b/lib.c @@ -276,7 +276,6 @@ int Winit_cstring = 0; int Wint_to_pointer_cast = 1; int Wenum_mismatch = 1; int Wexternal_function_has_definition = 1; -int Wsparse_error = 0; int Wmemcpy_max_count = 1; int Wnewline_eof = 1; int Wnon_pointer_null = 1; @@ -296,6 +295,7 @@ int Wshadow = 0; int Wshift_count_negative = 1; int Wshift_count_overflow = 1; int Wsizeof_bool = 0; +int Wsparse_error = WARNING_FORCE_OFF; int Wstrict_prototypes = 1; int Wtautological_compare = 0; int Wtransparent_union = 0; @@ -793,7 +793,7 @@ static char **handle_switch_W(char *arg, char **next) if (!strcmp(arg, "Wsparse-all")) { int i; for (i = 0; warnings[i].name; i++) { - if (*warnings[i].flag != WARNING_FORCE_OFF && warnings[i].flag != &Wsparse_error) + if (*warnings[i].flag != WARNING_FORCE_OFF) *warnings[i].flag = WARNING_ON; } } From patchwork Sun Jul 5 13:02:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11644381 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8707513B4 for ; Sun, 5 Jul 2020 13:02:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6F88E20747 for ; Sun, 5 Jul 2020 13:02:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lf/kw4jm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726957AbgGENCe (ORCPT ); Sun, 5 Jul 2020 09:02:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726792AbgGENCe (ORCPT ); Sun, 5 Jul 2020 09:02:34 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3448C061794 for ; Sun, 5 Jul 2020 06:02:33 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id d16so25544919edz.12 for ; Sun, 05 Jul 2020 06:02:33 -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 :mime-version:content-transfer-encoding; bh=26ZiewEHNxWX5EAuv9sa51RYGJG4O6qcJfTfVaArce0=; b=lf/kw4jmFI+1I8/5h62irQuzXUYqy4sFeN0Wt26nqmAXbchRJYi62NLxcpUThP93RU pfJIUt+EAHyljvY7LWbDoBBVW04LpdQ37kjZ5+1stVQzltyis0IYR905DYfKI4WkYa50 ZlehkVrntxXLNPelyWvXhOJMk+64AnxshF9PxuFg/owBP5hEwQGjs5I2+Gp9Ja/1VtqK CvkioqKAHTSprgVHioaKCyqck5hjvhuoh/RfmnxdE2TjpxuPRl48NGRA/irp90U1hzNt Jc/976hw5TL72CJZB2I6vsJ2AZFJNRBFRVXmeLagtt7dsBHefkiu/bXIbOCYcPTAV/SY pAbQ== 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:mime-version:content-transfer-encoding; bh=26ZiewEHNxWX5EAuv9sa51RYGJG4O6qcJfTfVaArce0=; b=ibuBwpaGauF7O3Gd+IB8cv87kq8kL5mcm0kGu064u+Hi6geMkwrsX5ZuOrBE4J9qJ/ as3TWDmT+7OZ4USlGYvW85ZXKVprJAiPM2Xe3yuW3xkKQH9AuZ8kIcWf5SDCpqWq3tjj ovpmTVHDz8UcbfFTP5MH4/vvPcIj7vazZX1K7uJHgeYXj7uGbPtzxI3UZhquIKQBj8// 6dEzFnxu8QOmqiMsTA4RR598TMglNM68KTMggFcgzV/bzOP0vEU4ym9cvGgASwPCdMkK UIFHcqBKbYTgtbqPYzUpRizMo/RdgWpkQOosvW21XlbvZE2oxgwf1orKyrMQX1dnUcKx i5MA== X-Gm-Message-State: AOAM532UY8aS5EhSB3KDg/rAGwq7KsU3CDcBat7VxGYQugJUpbI8dDTD 8FybfmetFT8JEC2dafMedhdTEBr2 X-Google-Smtp-Source: ABdhPJxy8HMSRw8WqU5rlEtwAi7ZtbpecIYuYAXOiL23w5xIgldHxUW+DpD6+90RX5pak9dLoWD1Rw== X-Received: by 2002:a50:fc97:: with SMTP id f23mr41005768edq.255.1593954152190; Sun, 05 Jul 2020 06:02:32 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7f9:7600:a542:d3fb:b75a:dec5]) by smtp.gmail.com with ESMTPSA id x16sm19535945edr.52.2020.07.05.06.02.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jul 2020 06:02:31 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 05/15] options: handle_onoff_switch() can handle any flags, not only warnings Date: Sun, 5 Jul 2020 15:02:10 +0200 Message-Id: <20200705130220.26230-6-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> References: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org So, use 'flag' instead of 'warning' for variable and function names. Signed-off-by: Luc Van Oostenryck --- lib.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib.c b/lib.c index 9acdc60fc416..c27773097127 100644 --- a/lib.c +++ b/lib.c @@ -250,10 +250,10 @@ void die(const char *fmt, ...) static struct token *pre_buffer_begin = NULL; static struct token *pre_buffer_end = NULL; -enum warning_type { - WARNING_OFF, - WARNING_ON, - WARNING_FORCE_OFF +enum flag_type { + FLAG_OFF, + FLAG_ON, + FLAG_FORCE_OFF }; int Waddress = 0; @@ -295,7 +295,7 @@ int Wshadow = 0; int Wshift_count_negative = 1; int Wshift_count_overflow = 1; int Wsizeof_bool = 0; -int Wsparse_error = WARNING_FORCE_OFF; +int Wsparse_error = FLAG_FORCE_OFF; int Wstrict_prototypes = 1; int Wtautological_compare = 0; int Wtransparent_union = 0; @@ -529,9 +529,9 @@ static int opt_##NAME(const char *arg, const char *opt, TYPE *ptr, int flag) \ OPT_NUMERIC(ullong, unsigned long long, strtoull) OPT_NUMERIC(uint, unsigned int, strtoul) -static char **handle_onoff_switch(char *arg, char **next, const struct flag warnings[]) +static char **handle_onoff_switch(char *arg, char **next, const struct flag flags[]) { - int flag = WARNING_ON; + int flag = FLAG_ON; char *p = arg + 1; unsigned i; @@ -540,12 +540,12 @@ static char **handle_onoff_switch(char *arg, char **next, const struct flag warn p += 2; if (p[0] == '-') p++; - flag = WARNING_FORCE_OFF; + flag = FLAG_FORCE_OFF; } - for (i = 0; warnings[i].name; i++) { - if (!strcmp(p,warnings[i].name)) { - *warnings[i].flag = flag; + for (i = 0; flags[i].name; i++) { + if (!strcmp(p,flags[i].name)) { + *flags[i].flag = flag; return next; } } @@ -722,7 +722,7 @@ static char **handle_switch_o(char *arg, char **next) } static const struct flag pflags[] = { - { "pedantic", &Wpedantic, NULL, OPT_VAL, WARNING_ON }, + { "pedantic", &Wpedantic, NULL, OPT_VAL, FLAG_ON }, { } }; @@ -793,8 +793,8 @@ static char **handle_switch_W(char *arg, char **next) if (!strcmp(arg, "Wsparse-all")) { int i; for (i = 0; warnings[i].name; i++) { - if (*warnings[i].flag != WARNING_FORCE_OFF) - *warnings[i].flag = WARNING_ON; + if (*warnings[i].flag != FLAG_FORCE_OFF) + *warnings[i].flag = FLAG_ON; } } @@ -858,13 +858,13 @@ static char **handle_switch_d(char *arg, char **next) } -static void handle_onoff_switch_finalize(const struct flag warnings[]) +static void handle_onoff_switch_finalize(const struct flag flags[]) { unsigned i; - for (i = 0; warnings[i].name; i++) { - if (*warnings[i].flag == WARNING_FORCE_OFF) - *warnings[i].flag = WARNING_OFF; + for (i = 0; flags[i].name; i++) { + if (*flags[i].flag == FLAG_FORCE_OFF) + *flags[i].flag = FLAG_OFF; } } From patchwork Sun Jul 5 13:02:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11644383 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A35EE92A for ; Sun, 5 Jul 2020 13:02:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8BEF120747 for ; Sun, 5 Jul 2020 13:02:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cV0kYtma" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726961AbgGENCf (ORCPT ); Sun, 5 Jul 2020 09:02:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726792AbgGENCf (ORCPT ); Sun, 5 Jul 2020 09:02:35 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC7D9C061794 for ; Sun, 5 Jul 2020 06:02:34 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id w16so39593499ejj.5 for ; Sun, 05 Jul 2020 06:02:34 -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 :mime-version:content-transfer-encoding; bh=vhOexs42tN8O73J1HULhVDqy4cxDIEcuMkt/q9iXBcE=; b=cV0kYtmaDWh1jNMbRL7NpL1ephDsNrHZEIxo58PH8UtptqsdOSw2/zWEtlSvakfM3M tLjiiWAKxWicA/Uaxp1lelLnHk4ciLlZ9CF1uy57nY58JWtXbIklHaQcv1XGdUNgAGJ/ JLSKlVRE/szK3sVHvesEQ8Nwg+pmz7074+q8Sw7NCGKG7alFTVk0xDxYmnQDpUAeFU1I Lm58ZyzbUisL+imyV/vbue3Dvv3vB0vyCRNsGzMYIJtl4CLGxCB0amvRmTI9YOPdxrJX +3Hsbnub+VFpcM7hsc3URN39xwQFbOga/l3mbQkKP219yZbAqVEOXe/PhCMnXUwXemIN rteQ== 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:mime-version:content-transfer-encoding; bh=vhOexs42tN8O73J1HULhVDqy4cxDIEcuMkt/q9iXBcE=; b=fDZmIEaG9VXvJYLQ7APMvFlKR0ZK+CH73rF6pi+uJsE3xp2CTi7263l4bQuiv5A3of iflRdSuCHxeGRXQoMCxoXDumT2MvIrvn5zhL43ffdKrwcLyQS6C3m07FUbuTbyeBvIz2 3qq6zd9v95p338VUq7+jHuGZisoDq8FdqXjto1KBtHBZKe6uhpbEnOlDo6rxcifFWpjr e656xRxk9/aXyvKpDJTufmN/ATo8nPgCGgxHg2pDZ1Dbn+oKs8tIVPIZQY7lrOFQ2phr vwXZmHXsAIeQJI4g2orTU0XzLR7RfVOKDKMT+OcXmcpoFCTuTTyhG+8CeWox3X7t/Icy sbfA== X-Gm-Message-State: AOAM532Lc+D0xGgBSdpOv3jQaZYjB/6fB9oSTJixWoT/5CLuth4x39Ps aAjXmx3UMTw9w7AF7USHlDwxbto6 X-Google-Smtp-Source: ABdhPJxLthPCH4DIWOJYBFpTFPieUOo0PNNhGaIn1yqd51hMmAZO5tv3KmiGonBqhjahWCIgBCDa0w== X-Received: by 2002:a17:906:3a17:: with SMTP id z23mr30203297eje.238.1593954153219; Sun, 05 Jul 2020 06:02:33 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7f9:7600:a542:d3fb:b75a:dec5]) by smtp.gmail.com with ESMTPSA id x16sm19535945edr.52.2020.07.05.06.02.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jul 2020 06:02:32 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 06/15] options: move helpers up Date: Sun, 5 Jul 2020 15:02:11 +0200 Message-Id: <20200705130220.26230-7-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> References: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org The helpers for parsing the options are often situated just above the first function using them. As result, these helpers can be found a bit everywhere in the code, it's messy and doesn't help to reuse these helpers. So, move all these helpers to the top. Signed-off-by: Luc Van Oostenryck --- lib.c | 87 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/lib.c b/lib.c index c27773097127..4868154fa3de 100644 --- a/lib.c +++ b/lib.c @@ -364,6 +364,15 @@ void add_pre_buffer(const char *fmt, ...) //////////////////////////////////////////////////////////////////////////////// // Helpers for option parsing +static const char *match_option(const char *arg, const char *prefix) +{ + unsigned int n = strlen(prefix); + if (strncmp(arg, prefix, n) == 0) + return arg + n; + return NULL; +} + + struct val_map { const char *name; int val; @@ -438,14 +447,6 @@ end: } -static const char *match_option(const char *arg, const char *prefix) -{ - unsigned int n = strlen(prefix); - if (strncmp(arg, prefix, n) == 0) - return arg + n; - return NULL; -} - #define OPT_INVERSE 1 #define OPT_VAL 2 struct flag { @@ -497,6 +498,41 @@ static int handle_switches(const char *ori, const char *opt, const struct flag * return 0; } +static char **handle_onoff_switch(char *arg, char **next, const struct flag flags[]) +{ + int flag = FLAG_ON; + char *p = arg + 1; + unsigned i; + + // Prefixes "no" and "no-" mean to turn warning off. + if (p[0] == 'n' && p[1] == 'o') { + p += 2; + if (p[0] == '-') + p++; + flag = FLAG_FORCE_OFF; + } + + for (i = 0; flags[i].name; i++) { + if (!strcmp(p,flags[i].name)) { + *flags[i].flag = flag; + return next; + } + } + + // Unknown. + return NULL; +} + +static void handle_onoff_switch_finalize(const struct flag flags[]) +{ + unsigned i; + + for (i = 0; flags[i].name; i++) { + if (*flags[i].flag == FLAG_FORCE_OFF) + *flags[i].flag = FLAG_OFF; + } +} + static int handle_switch_setval(const char *arg, const char *opt, const struct flag *flag, int options) { *(flag->flag) = flag->mask; @@ -529,31 +565,6 @@ static int opt_##NAME(const char *arg, const char *opt, TYPE *ptr, int flag) \ OPT_NUMERIC(ullong, unsigned long long, strtoull) OPT_NUMERIC(uint, unsigned int, strtoul) -static char **handle_onoff_switch(char *arg, char **next, const struct flag flags[]) -{ - int flag = FLAG_ON; - char *p = arg + 1; - unsigned i; - - // Prefixes "no" and "no-" mean to turn warning off. - if (p[0] == 'n' && p[1] == 'o') { - p += 2; - if (p[0] == '-') - p++; - flag = FLAG_FORCE_OFF; - } - - for (i = 0; flags[i].name; i++) { - if (!strcmp(p,flags[i].name)) { - *flags[i].flag = flag; - return next; - } - } - - // Unknown. - return NULL; -} - //////////////////////////////////////////////////////////////////////////////// // Option parsing @@ -858,16 +869,6 @@ static char **handle_switch_d(char *arg, char **next) } -static void handle_onoff_switch_finalize(const struct flag flags[]) -{ - unsigned i; - - for (i = 0; flags[i].name; i++) { - if (*flags[i].flag == FLAG_FORCE_OFF) - *flags[i].flag = FLAG_OFF; - } -} - static void handle_switch_W_finalize(void) { handle_onoff_switch_finalize(warnings); From patchwork Sun Jul 5 13:02:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11644385 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4914713B4 for ; Sun, 5 Jul 2020 13:02:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B59620747 for ; Sun, 5 Jul 2020 13:02:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HLOE/2CB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726964AbgGENCg (ORCPT ); Sun, 5 Jul 2020 09:02:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726792AbgGENCg (ORCPT ); Sun, 5 Jul 2020 09:02:36 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30A70C061794 for ; Sun, 5 Jul 2020 06:02:36 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id a8so30993309edy.1 for ; Sun, 05 Jul 2020 06:02:36 -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 :mime-version:content-transfer-encoding; bh=NsicvXfpt7PNM+/jTMxK0Bp4xt7OL8ToB67LePdR5mU=; b=HLOE/2CB8Rv1qhsk3ZWtbQtIztpFGOEoubTdmr4ABApNWttk/J92jW5ggNJ2x6oVbN o/BiiMtFQ/aVqkFI1y8ix48XFGyOytnMPiF4xNtlRsBX6FyKPZ9mtOppNPg9+GWYn2ec /9YeMs5rtcEJxO7mbSr2h0DhrdQex4gUpUHRhe5EpefD18LLIfTFY2ZT98UpjoeNqqNM oPrXc/cZldnWqUMgTwVRS3TKRSXu2tZ9rqo+6Mpdk3hEOhI1jAYFPmBhyxp2mDmqCBLD aVxiH8QYTHesrMg/6Ji8EuTVVAn10mGlRNjiB9i6L9vyou547CPtY6jKxybw3KX1kRGI eS8Q== 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:mime-version:content-transfer-encoding; bh=NsicvXfpt7PNM+/jTMxK0Bp4xt7OL8ToB67LePdR5mU=; b=V6T7JZzwFX4rvrCBXxhat4IcdGp4bZVvc5f6b57Jfmr5joRytIzWHYh3/5R4DSRGXw EFvQq9Kh9IK+9NzSoA79Z4ydX0Qzj/cFeBomHmgfLkTi3Qdi5y9lUg94eEAsB+ufRECZ YfaeRwXpqLCwt4o3xMomydqI9vgV7Cz2lezjEJ2DmfmMWx++FSdP7Up8XnslyONaA30K yKKBFtMAtD6cW1U5+XNwiBBYWrTZGhdM93YgC9MrKZOJe4QZol224nOg66BCttnr1CtE DqHakxTrQGZ20I+3JI2G/t6n3mmbMzuY676OwJLyj0bEOTNKQ8Oz5Qh8Vjswgy6l9UGd lzVg== X-Gm-Message-State: AOAM531VtC2L8q43h+xzeeveZPDuIZT6SYvK5nlgHqTIZJWfD1ZHv+cz g8G5govQe3TjfpLxGpn+PAMIepoU X-Google-Smtp-Source: ABdhPJyl6MENWLW2Zl337CMzqTIVL34Mhds+WJk83Xv4TAjY0bA7nTmZIMXRsiBLvNbG3QKpXJG/NQ== X-Received: by 2002:a50:ba8b:: with SMTP id x11mr51874178ede.201.1593954154350; Sun, 05 Jul 2020 06:02:34 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7f9:7600:a542:d3fb:b75a:dec5]) by smtp.gmail.com with ESMTPSA id x16sm19535945edr.52.2020.07.05.06.02.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jul 2020 06:02:33 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 07/15] options: alphasort the handle_switch_[a-zA_Z]() Date: Sun, 5 Jul 2020 15:02:12 +0200 Message-Id: <20200705130220.26230-8-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> References: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org These function have probably been added in 'historical order' and as result it's not easy to quickly see where they're defined. Change this arranging them in asciibetical order. Signed-off-by: Luc Van Oostenryck --- lib.c | 656 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 327 insertions(+), 329 deletions(-) diff --git a/lib.c b/lib.c index 4868154fa3de..5f4e6b2d76c8 100644 --- a/lib.c +++ b/lib.c @@ -568,6 +568,14 @@ OPT_NUMERIC(uint, unsigned int, strtoul) //////////////////////////////////////////////////////////////////////////////// // Option parsing +static char **handle_switch_a(char *arg, char **next) +{ + if (!strcmp (arg, "ansi")) + standard = STANDARD_C89; + + return next; +} + static char **handle_switch_D(char *arg, char **next) { const char *name = arg + 1; @@ -595,6 +603,37 @@ static char **handle_switch_D(char *arg, char **next) return next; } +static char **handle_switch_d(char *arg, char **next) +{ + char *arg_char = arg + 1; + + /* + * -d, where is a sequence of characters, not preceded + * by a space. If you specify characters whose behaviour conflicts, + * the result is undefined. + */ + while (*arg_char) { + switch (*arg_char) { + case 'M': /* dump just the macro definitions */ + dump_macros_only = 1; + dump_macro_defs = 0; + break; + case 'D': /* like 'M', but also output pre-processed text */ + dump_macro_defs = 1; + dump_macros_only = 0; + break; + case 'N': /* like 'D', but only output macro names not bodies */ + break; + case 'I': /* like 'D', but also output #include directives */ + break; + case 'U': /* like 'D', but only output expanded macros */ + break; + } + arg_char++; + } + return next; +} + static char **handle_switch_E(char *arg, char **next) { if (arg[1] == '\0') @@ -602,6 +641,146 @@ static char **handle_switch_E(char *arg, char **next) return next; } +static int handle_ftabstop(const char *arg, const char *opt, const struct flag *flag, int options) +{ + unsigned long val; + char *end; + + if (*opt == '\0') + die("error: missing argument to \"%s\"", arg); + + /* we silently ignore silly values */ + val = strtoul(opt, &end, 10); + if (*end == '\0' && 1 <= val && val <= 100) + tabstop = val; + + return 1; +} + +static int handle_fpasses(const char *arg, const char *opt, const struct flag *flag, int options) +{ + unsigned long mask; + + mask = flag->mask; + if (*opt == '\0') { + if (options & OPT_INVERSE) + fpasses &= ~mask; + else + fpasses |= mask; + return 1; + } + if (options & OPT_INVERSE) + return 0; + if (!strcmp(opt, "-enable")) { + fpasses |= mask; + return 1; + } + if (!strcmp(opt, "-disable")) { + fpasses &= ~mask; + return 1; + } + if (!strcmp(opt, "=last")) { + // clear everything above + mask |= mask - 1; + fpasses &= mask; + return 1; + } + return 0; +} + +static int handle_fdiagnostic_prefix(const char *arg, const char *opt, const struct flag *flag, int options) +{ + switch (*opt) { + case '\0': + diag_prefix = "sparse: "; + return 1; + case '=': + diag_prefix = xasprintf("%s: ", opt+1); + return 1; + default: + return 0; + } +} + +static int handle_fdump_ir(const char *arg, const char *opt, const struct flag *flag, int options) +{ + static const struct mask_map dump_ir_options[] = { + { "", PASS_LINEARIZE }, + { "linearize", PASS_LINEARIZE }, + { "mem2reg", PASS_MEM2REG }, + { "final", PASS_FINAL }, + { }, + }; + + return handle_suboption_mask(arg, opt, dump_ir_options, &fdump_ir); +} + +static int handle_fmemcpy_max_count(const char *arg, const char *opt, const struct flag *flag, int options) +{ + opt_ullong(arg, opt, &fmemcpy_max_count, OPTNUM_ZERO_IS_INF|OPTNUM_UNLIMITED); + return 1; +} + +static int handle_fmax_warnings(const char *arg, const char *opt, const struct flag *flag, int options) +{ + opt_uint(arg, opt, &fmax_warnings, OPTNUM_UNLIMITED); + return 1; +} + +static struct flag fflags[] = { + { "diagnostic-prefix", NULL, handle_fdiagnostic_prefix }, + { "dump-ir", NULL, handle_fdump_ir }, + { "freestanding", &fhosted, NULL, OPT_INVERSE }, + { "hosted", &fhosted }, + { "linearize", NULL, handle_fpasses, PASS_LINEARIZE }, + { "max-warnings=", NULL, handle_fmax_warnings }, + { "mem-report", &fmem_report }, + { "memcpy-max-count=", NULL, handle_fmemcpy_max_count }, + { "tabstop=", NULL, handle_ftabstop }, + { "mem2reg", NULL, handle_fpasses, PASS_MEM2REG }, + { "optim", NULL, handle_fpasses, PASS_OPTIM }, + { "pic", &fpic, handle_switch_setval, 1 }, + { "PIC", &fpic, handle_switch_setval, 2 }, + { "pie", &fpie, handle_switch_setval, 1 }, + { "PIE", &fpie, handle_switch_setval, 2 }, + { "signed-char", &funsigned_char, NULL, OPT_INVERSE }, + { "short-wchar", &fshort_wchar }, + { "unsigned-char", &funsigned_char, NULL, }, + { }, +}; + +static char **handle_switch_f(char *arg, char **next) +{ + if (handle_switches(arg-1, arg+1, fflags)) + return next; + + return next; +} + +static char **handle_switch_G(char *arg, char **next) +{ + if (!strcmp (arg, "G") && *next) + return next + 1; // "-G 0" + else + return next; // "-G0" or (bogus) terminal "-G" +} + +static char **handle_base_dir(char *arg, char **next) +{ + gcc_base_dir = *++next; + if (!gcc_base_dir) + die("missing argument for -gcc-base-dir option"); + return next; +} + +static char **handle_switch_g(char *arg, char **next) +{ + if (!strcmp (arg, "gcc-base-dir")) + return handle_base_dir(arg, next); + + return next; +} + static char **handle_switch_I(char *arg, char **next) { char *path = arg+1; @@ -659,15 +838,7 @@ static char **handle_switch_M(char *arg, char **next) return next; } -static char **handle_multiarch_dir(char *arg, char **next) -{ - multiarch_dir = *++next; - if (!multiarch_dir) - die("missing argument for -multiarch-dir option"); - return next; -} - -static int handle_cmodel(const char *opt, const char *arg, const struct flag *flag, int options) +static int handle_mcmodel(const char *opt, const char *arg, const struct flag *flag, int options) { static const struct val_map cmodels[] = { { "kernel", CMODEL_KERNEL }, @@ -682,7 +853,7 @@ static int handle_cmodel(const char *opt, const char *arg, const struct flag *fl return handle_subopt_val(opt, arg, cmodels, flag->flag); } -static int handle_float_abi(const char *opt, const char *arg, const struct flag *flag, int options) { +static int handle_mfloat_abi(const char *opt, const char *arg, const struct flag *flag, int options) { static const struct val_map fp_abis[] = { { "hard", FP_ABI_HARD }, { "soft", FP_ABI_SOFT }, @@ -692,6 +863,14 @@ static int handle_float_abi(const char *opt, const char *arg, const struct flag return handle_subopt_val(opt, arg, fp_abis, flag->flag); } +static char **handle_multiarch_dir(char *arg, char **next) +{ + multiarch_dir = *++next; + if (!multiarch_dir) + die("missing argument for -multiarch-dir option"); + return next; +} + static const struct flag mflags[] = { { "64", &arch_m64, NULL, OPT_VAL, ARCH_LP64 }, { "32", &arch_m64, NULL, OPT_VAL, ARCH_LP32 }, @@ -702,8 +881,8 @@ static const struct flag mflags[] = { { "size-long", &arch_msize_long }, { "big-endian", &arch_big_endian, NULL }, { "little-endian", &arch_big_endian, NULL, OPT_INVERSE }, - { "cmodel", &arch_cmodel, handle_cmodel }, - { "float-abi", &arch_fp_abi, handle_float_abi }, + { "cmodel", &arch_cmodel, handle_mcmodel }, + { "float-abi", &arch_fp_abi, handle_mfloat_abi }, { "hard-float", &arch_fp_abi, NULL, OPT_VAL, FP_ABI_HARD }, { "soft-float", &arch_fp_abi, NULL, OPT_VAL, FP_ABI_SOFT }, { } @@ -720,6 +899,30 @@ static char **handle_switch_m(char *arg, char **next) return next; } +static char **handle_nostdinc(char *arg, char **next) +{ + add_pre_buffer("#nostdinc\n"); + return next; +} + +static char **handle_switch_n(char *arg, char **next) +{ + if (!strcmp (arg, "nostdinc")) + return handle_nostdinc(arg, next); + + return next; +} + +static char **handle_switch_O(char *arg, char **next) +{ + int level = 1; + if (arg[1] >= '0' && arg[1] <= '9') + level = arg[1] - '0'; + optimize_level = level; + optimize_size = arg[1] == 's'; + return next; +} + static char **handle_switch_o(char *arg, char **next) { if (!strcmp (arg, "o")) { // "-o foo" @@ -743,304 +946,6 @@ static char **handle_switch_p(char *arg, char **next) return next; } -static const struct flag warnings[] = { - { "address", &Waddress }, - { "address-space", &Waddress_space }, - { "bitwise", &Wbitwise }, - { "bitwise-pointer", &Wbitwise_pointer}, - { "cast-from-as", &Wcast_from_as }, - { "cast-to-as", &Wcast_to_as }, - { "cast-truncate", &Wcast_truncate }, - { "constant-suffix", &Wconstant_suffix }, - { "constexpr-not-const", &Wconstexpr_not_const}, - { "context", &Wcontext }, - { "decl", &Wdecl }, - { "declaration-after-statement", &Wdeclarationafterstatement }, - { "default-bitfield-sign", &Wdefault_bitfield_sign }, - { "designated-init", &Wdesignated_init }, - { "do-while", &Wdo_while }, - { "enum-mismatch", &Wenum_mismatch }, - { "external-function-has-definition", &Wexternal_function_has_definition }, - { "implicit-int", &Wimplicit_int }, - { "init-cstring", &Winit_cstring }, - { "int-to-pointer-cast", &Wint_to_pointer_cast }, - { "memcpy-max-count", &Wmemcpy_max_count }, - { "non-pointer-null", &Wnon_pointer_null }, - { "newline-eof", &Wnewline_eof }, - { "old-initializer", &Wold_initializer }, - { "old-style-definition", &Wold_style_definition }, - { "one-bit-signed-bitfield", &Wone_bit_signed_bitfield }, - { "override-init", &Woverride_init }, - { "override-init-all", &Woverride_init_all }, - { "paren-string", &Wparen_string }, - { "pedantic", &Wpedantic }, - { "pointer-to-int-cast", &Wpointer_to_int_cast }, - { "ptr-subtraction-blows", &Wptr_subtraction_blows }, - { "return-void", &Wreturn_void }, - { "shadow", &Wshadow }, - { "shift-count-negative", &Wshift_count_negative }, - { "shift-count-overflow", &Wshift_count_overflow }, - { "sizeof-bool", &Wsizeof_bool }, - { "strict-prototypes", &Wstrict_prototypes }, - { "pointer-arith", &Wpointer_arith }, - { "sparse-error", &Wsparse_error }, - { "tautological-compare", &Wtautological_compare }, - { "transparent-union", &Wtransparent_union }, - { "typesign", &Wtypesign }, - { "undef", &Wundef }, - { "uninitialized", &Wuninitialized }, - { "universal-initializer", &Wuniversal_initializer }, - { "unknown-attribute", &Wunknown_attribute }, - { "vla", &Wvla }, - { } -}; - -static char **handle_switch_W(char *arg, char **next) -{ - char ** ret = handle_onoff_switch(arg, next, warnings); - if (ret) - return ret; - - if (!strcmp(arg, "Wsparse-all")) { - int i; - for (i = 0; warnings[i].name; i++) { - if (*warnings[i].flag != FLAG_FORCE_OFF) - *warnings[i].flag = FLAG_ON; - } - } - - // Unknown. - return next; -} - -static struct flag debugs[] = { - { "compound", &dbg_compound}, - { "dead", &dbg_dead}, - { "domtree", &dbg_domtree}, - { "entry", &dbg_entry}, - { "ir", &dbg_ir}, - { "postorder", &dbg_postorder}, - { } -}; - - -static char **handle_switch_v(char *arg, char **next) -{ - char ** ret = handle_onoff_switch(arg, next, debugs); - if (ret) - return ret; - - // Unknown. - do { - verbose++; - } while (*++arg == 'v'); - return next; -} - -static char **handle_switch_d(char *arg, char **next) -{ - char *arg_char = arg + 1; - - /* - * -d, where is a sequence of characters, not preceded - * by a space. If you specify characters whose behaviour conflicts, - * the result is undefined. - */ - while (*arg_char) { - switch (*arg_char) { - case 'M': /* dump just the macro definitions */ - dump_macros_only = 1; - dump_macro_defs = 0; - break; - case 'D': /* like 'M', but also output pre-processed text */ - dump_macro_defs = 1; - dump_macros_only = 0; - break; - case 'N': /* like 'D', but only output macro names not bodies */ - break; - case 'I': /* like 'D', but also output #include directives */ - break; - case 'U': /* like 'D', but only output expanded macros */ - break; - } - arg_char++; - } - return next; -} - - -static void handle_switch_W_finalize(void) -{ - handle_onoff_switch_finalize(warnings); - - /* default Wdeclarationafterstatement based on the C dialect */ - if (-1 == Wdeclarationafterstatement) { - switch (standard) { - case STANDARD_C89: - case STANDARD_C94: - Wdeclarationafterstatement = 1; - break; - default: - Wdeclarationafterstatement = 0; - break; - } - } -} - -static void handle_switch_v_finalize(void) -{ - handle_onoff_switch_finalize(debugs); -} - -static char **handle_switch_U(char *arg, char **next) -{ - const char *name = arg + 1; - add_pre_buffer ("#undef %s\n", name); - return next; -} - -static char **handle_switch_O(char *arg, char **next) -{ - int level = 1; - if (arg[1] >= '0' && arg[1] <= '9') - level = arg[1] - '0'; - optimize_level = level; - optimize_size = arg[1] == 's'; - return next; -} - -static int handle_ftabstop(const char *arg, const char *opt, const struct flag *flag, int options) -{ - unsigned long val; - char *end; - - if (*opt == '\0') - die("error: missing argument to \"%s\"", arg); - - /* we silently ignore silly values */ - val = strtoul(opt, &end, 10); - if (*end == '\0' && 1 <= val && val <= 100) - tabstop = val; - - return 1; -} - -static int handle_fpasses(const char *arg, const char *opt, const struct flag *flag, int options) -{ - unsigned long mask; - - mask = flag->mask; - if (*opt == '\0') { - if (options & OPT_INVERSE) - fpasses &= ~mask; - else - fpasses |= mask; - return 1; - } - if (options & OPT_INVERSE) - return 0; - if (!strcmp(opt, "-enable")) { - fpasses |= mask; - return 1; - } - if (!strcmp(opt, "-disable")) { - fpasses &= ~mask; - return 1; - } - if (!strcmp(opt, "=last")) { - // clear everything above - mask |= mask - 1; - fpasses &= mask; - return 1; - } - return 0; -} - -static int handle_fdiagnostic_prefix(const char *arg, const char *opt, const struct flag *flag, int options) -{ - switch (*opt) { - case '\0': - diag_prefix = "sparse: "; - return 1; - case '=': - diag_prefix = xasprintf("%s: ", opt+1); - return 1; - default: - return 0; - } -} - -static int handle_fdump_ir(const char *arg, const char *opt, const struct flag *flag, int options) -{ - static const struct mask_map dump_ir_options[] = { - { "", PASS_LINEARIZE }, - { "linearize", PASS_LINEARIZE }, - { "mem2reg", PASS_MEM2REG }, - { "final", PASS_FINAL }, - { }, - }; - - return handle_suboption_mask(arg, opt, dump_ir_options, &fdump_ir); -} - -static int handle_fmemcpy_max_count(const char *arg, const char *opt, const struct flag *flag, int options) -{ - opt_ullong(arg, opt, &fmemcpy_max_count, OPTNUM_ZERO_IS_INF|OPTNUM_UNLIMITED); - return 1; -} - -static int handle_fmax_warnings(const char *arg, const char *opt, const struct flag *flag, int options) -{ - opt_uint(arg, opt, &fmax_warnings, OPTNUM_UNLIMITED); - return 1; -} - -static struct flag fflags[] = { - { "diagnostic-prefix", NULL, handle_fdiagnostic_prefix }, - { "dump-ir", NULL, handle_fdump_ir }, - { "freestanding", &fhosted, NULL, OPT_INVERSE }, - { "hosted", &fhosted }, - { "linearize", NULL, handle_fpasses, PASS_LINEARIZE }, - { "max-warnings=", NULL, handle_fmax_warnings }, - { "mem-report", &fmem_report }, - { "memcpy-max-count=", NULL, handle_fmemcpy_max_count }, - { "tabstop=", NULL, handle_ftabstop }, - { "mem2reg", NULL, handle_fpasses, PASS_MEM2REG }, - { "optim", NULL, handle_fpasses, PASS_OPTIM }, - { "pic", &fpic, handle_switch_setval, 1 }, - { "PIC", &fpic, handle_switch_setval, 2 }, - { "pie", &fpie, handle_switch_setval, 1 }, - { "PIE", &fpie, handle_switch_setval, 2 }, - { "signed-char", &funsigned_char, NULL, OPT_INVERSE }, - { "short-wchar", &fshort_wchar }, - { "unsigned-char", &funsigned_char, NULL, }, - { }, -}; - -static char **handle_switch_f(char *arg, char **next) -{ - if (handle_switches(arg-1, arg+1, fflags)) - return next; - - return next; -} - -static char **handle_switch_G(char *arg, char **next) -{ - if (!strcmp (arg, "G") && *next) - return next + 1; // "-G 0" - else - return next; // "-G0" or (bogus) terminal "-G" -} - -static char **handle_switch_a(char *arg, char **next) -{ - if (!strcmp (arg, "ansi")) - standard = STANDARD_C89; - - return next; -} - static char **handle_switch_s(const char *arg, char **next) { if ((arg = match_option(arg, "std="))) { @@ -1087,36 +992,129 @@ static char **handle_switch_s(const char *arg, char **next) return next; } -static char **handle_nostdinc(char *arg, char **next) +static char **handle_switch_U(char *arg, char **next) { - add_pre_buffer("#nostdinc\n"); + const char *name = arg + 1; + add_pre_buffer ("#undef %s\n", name); return next; } -static char **handle_switch_n(char *arg, char **next) +static struct flag debugs[] = { + { "compound", &dbg_compound}, + { "dead", &dbg_dead}, + { "domtree", &dbg_domtree}, + { "entry", &dbg_entry}, + { "ir", &dbg_ir}, + { "postorder", &dbg_postorder}, + { } +}; + +static char **handle_switch_v(char *arg, char **next) { - if (!strcmp (arg, "nostdinc")) - return handle_nostdinc(arg, next); + char ** ret = handle_onoff_switch(arg, next, debugs); + if (ret) + return ret; + // Unknown. + do { + verbose++; + } while (*++arg == 'v'); return next; } -static char **handle_base_dir(char *arg, char **next) +static void handle_switch_v_finalize(void) { - gcc_base_dir = *++next; - if (!gcc_base_dir) - die("missing argument for -gcc-base-dir option"); - return next; + handle_onoff_switch_finalize(debugs); } -static char **handle_switch_g(char *arg, char **next) +static const struct flag warnings[] = { + { "address", &Waddress }, + { "address-space", &Waddress_space }, + { "bitwise", &Wbitwise }, + { "bitwise-pointer", &Wbitwise_pointer}, + { "cast-from-as", &Wcast_from_as }, + { "cast-to-as", &Wcast_to_as }, + { "cast-truncate", &Wcast_truncate }, + { "constant-suffix", &Wconstant_suffix }, + { "constexpr-not-const", &Wconstexpr_not_const}, + { "context", &Wcontext }, + { "decl", &Wdecl }, + { "declaration-after-statement", &Wdeclarationafterstatement }, + { "default-bitfield-sign", &Wdefault_bitfield_sign }, + { "designated-init", &Wdesignated_init }, + { "do-while", &Wdo_while }, + { "enum-mismatch", &Wenum_mismatch }, + { "external-function-has-definition", &Wexternal_function_has_definition }, + { "implicit-int", &Wimplicit_int }, + { "init-cstring", &Winit_cstring }, + { "int-to-pointer-cast", &Wint_to_pointer_cast }, + { "memcpy-max-count", &Wmemcpy_max_count }, + { "non-pointer-null", &Wnon_pointer_null }, + { "newline-eof", &Wnewline_eof }, + { "old-initializer", &Wold_initializer }, + { "old-style-definition", &Wold_style_definition }, + { "one-bit-signed-bitfield", &Wone_bit_signed_bitfield }, + { "override-init", &Woverride_init }, + { "override-init-all", &Woverride_init_all }, + { "paren-string", &Wparen_string }, + { "pedantic", &Wpedantic }, + { "pointer-to-int-cast", &Wpointer_to_int_cast }, + { "ptr-subtraction-blows", &Wptr_subtraction_blows }, + { "return-void", &Wreturn_void }, + { "shadow", &Wshadow }, + { "shift-count-negative", &Wshift_count_negative }, + { "shift-count-overflow", &Wshift_count_overflow }, + { "sizeof-bool", &Wsizeof_bool }, + { "strict-prototypes", &Wstrict_prototypes }, + { "pointer-arith", &Wpointer_arith }, + { "sparse-error", &Wsparse_error }, + { "tautological-compare", &Wtautological_compare }, + { "transparent-union", &Wtransparent_union }, + { "typesign", &Wtypesign }, + { "undef", &Wundef }, + { "uninitialized", &Wuninitialized }, + { "universal-initializer", &Wuniversal_initializer }, + { "unknown-attribute", &Wunknown_attribute }, + { "vla", &Wvla }, + { } +}; + +static char **handle_switch_W(char *arg, char **next) { - if (!strcmp (arg, "gcc-base-dir")) - return handle_base_dir(arg, next); + char ** ret = handle_onoff_switch(arg, next, warnings); + if (ret) + return ret; + if (!strcmp(arg, "Wsparse-all")) { + int i; + for (i = 0; warnings[i].name; i++) { + if (*warnings[i].flag != FLAG_FORCE_OFF) + *warnings[i].flag = FLAG_ON; + } + } + + // Unknown. return next; } +static void handle_switch_W_finalize(void) +{ + handle_onoff_switch_finalize(warnings); + + /* default Wdeclarationafterstatement based on the C dialect */ + if (-1 == Wdeclarationafterstatement) { + switch (standard) { + case STANDARD_C89: + case STANDARD_C94: + Wdeclarationafterstatement = 1; + break; + default: + Wdeclarationafterstatement = 0; + break; + } + } +} + static char **handle_switch_x(char *arg, char **next) { if (!*++next) @@ -1139,12 +1137,6 @@ static char **handle_arch(char *arg, char **next) return next; } -static char **handle_version(char *arg, char **next) -{ - printf("%s\n", SPARSE_VERSION); - exit(0); -} - static char **handle_param(char *arg, char **next) { char *value = NULL; @@ -1162,6 +1154,12 @@ static char **handle_param(char *arg, char **next) return next; } +static char **handle_version(char *arg, char **next) +{ + printf("%s\n", SPARSE_VERSION); + exit(0); +} + struct switches { const char *name; char **(*fn)(char *, char **); From patchwork Sun Jul 5 13:02:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11644387 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6CCF114DD for ; Sun, 5 Jul 2020 13:02:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 54EF52075D for ; Sun, 5 Jul 2020 13:02:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sjnNXU2E" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726792AbgGENCh (ORCPT ); Sun, 5 Jul 2020 09:02:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726962AbgGENCg (ORCPT ); Sun, 5 Jul 2020 09:02:36 -0400 Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A431C08C5DE for ; Sun, 5 Jul 2020 06:02:36 -0700 (PDT) Received: by mail-ed1-x541.google.com with SMTP id by13so22328544edb.11 for ; Sun, 05 Jul 2020 06:02:36 -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 :mime-version:content-transfer-encoding; bh=VHCTMmbjnxLnBVTnwczuP/hIItaJS+A9i2ZXuCEHkYs=; b=sjnNXU2EUDiSR25ropg7j59VBAaU+8GpabD8uAH8guX3yAAwRxkWf9VITQkhC+Yvo1 1GF9F/K0lsPazUWaNHdj6z4b7Hgsu5LxMI92zajIyb2QjLgYcXnY4vDbmtE/scKaNt5k hBXVp6eyAI90ciD6EW2pCyEG6XIQG7e1SPnWwdh4pJTaXxK/EhCSODzkgYhBlDocXCEl n8vJQmlxe6oClUhn9V4mRLCFnA+/71WO2VoPNJZDMFnbsnY3ATQ41G6HLCbExjVEl6BU MQu2LP41Wk2aLLwB0xLnkgqtnYAJ4tqeX9VZfZPczBCEjvBHJ0EGyAmWhZ2oA6a0WmwJ cy6w== 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:mime-version:content-transfer-encoding; bh=VHCTMmbjnxLnBVTnwczuP/hIItaJS+A9i2ZXuCEHkYs=; b=ow0ch+77WluP+0f79JTUE1kjNN7DI9JmsGqxnysDjXqV+fbd4XidKHSHwOvxv0EHAO MC6eZ0V1eQcHKp5s/ckys0ACWeLpAAXzTAW/wr5QUR/voEU7T5/iZXGnjZs85pzHEdGk jRRe6Bfqy1hD15+2+zzNdlJ7/b2jHE5846hVTVEQxv1jYaNKrVimw2xEfx7ouwPeFdiA f5hZ3PI5SvI4eVJBfnZnViaaN8rX+xa7BfnO9GAyrfQztPMnqpgdjCafx3DwzYwoyMtf u903Q9vy84/l09Fn2zDX57homqnFMxkWzd3jgrvT011n7KW/VqDDzwQN2dLZTymvNz71 wKvA== X-Gm-Message-State: AOAM531yx3JsvQf67ZY+kzyNyGoqUn38U+bwssIoP7vFfg8C0iroNBAN 5N2Xkk+6mG4bXwaWTytJDEpWThkb X-Google-Smtp-Source: ABdhPJyoO8uTj2iSpZnixJ1Qg51aaR09UsS6PaO8g8ZV7hi8AngcxA/0U/DjaYdfLWjcJn7ZUvIMow== X-Received: by 2002:a05:6402:1592:: with SMTP id c18mr52080412edv.258.1593954155043; Sun, 05 Jul 2020 06:02:35 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7f9:7600:a542:d3fb:b75a:dec5]) by smtp.gmail.com with ESMTPSA id x16sm19535945edr.52.2020.07.05.06.02.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jul 2020 06:02:34 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 08/15] options: avoid spaces between function name and arguments list Date: Sun, 5 Jul 2020 15:02:13 +0200 Message-Id: <20200705130220.26230-9-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> References: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org It's a stylistic detail but a lot of the strcmp() calls used for the processing of the options are written 'strcmp (...)'. Two other functions calls are also in the case. Reformat them to the usual style for function calls: without the space between the function name and the arguments. Signed-off-by: Luc Van Oostenryck --- lib.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib.c b/lib.c index 5f4e6b2d76c8..b3bacb180cac 100644 --- a/lib.c +++ b/lib.c @@ -570,7 +570,7 @@ OPT_NUMERIC(uint, unsigned int, strtoul) static char **handle_switch_a(char *arg, char **next) { - if (!strcmp (arg, "ansi")) + if (!strcmp(arg, "ansi")) standard = STANDARD_C89; return next; @@ -759,7 +759,7 @@ static char **handle_switch_f(char *arg, char **next) static char **handle_switch_G(char *arg, char **next) { - if (!strcmp (arg, "G") && *next) + if (!strcmp(arg, "G") && *next) return next + 1; // "-G 0" else return next; // "-G0" or (bogus) terminal "-G" @@ -775,7 +775,7 @@ static char **handle_base_dir(char *arg, char **next) static char **handle_switch_g(char *arg, char **next) { - if (!strcmp (arg, "gcc-base-dir")) + if (!strcmp(arg, "gcc-base-dir")) return handle_base_dir(arg, next); return next; @@ -907,7 +907,7 @@ static char **handle_nostdinc(char *arg, char **next) static char **handle_switch_n(char *arg, char **next) { - if (!strcmp (arg, "nostdinc")) + if (!strcmp(arg, "nostdinc")) return handle_nostdinc(arg, next); return next; @@ -925,7 +925,7 @@ static char **handle_switch_O(char *arg, char **next) static char **handle_switch_o(char *arg, char **next) { - if (!strcmp (arg, "o")) { // "-o foo" + if (!strcmp(arg, "o")) { // "-o foo" if (!*++next) die("argument to '-o' is missing"); outfile = *next; @@ -949,23 +949,23 @@ static char **handle_switch_p(char *arg, char **next) static char **handle_switch_s(const char *arg, char **next) { if ((arg = match_option(arg, "std="))) { - if (!strcmp (arg, "c89") || - !strcmp (arg, "iso9899:1990")) + if (!strcmp(arg, "c89") || + !strcmp(arg, "iso9899:1990")) standard = STANDARD_C89; - else if (!strcmp (arg, "iso9899:199409")) + else if (!strcmp(arg, "iso9899:199409")) standard = STANDARD_C94; - else if (!strcmp (arg, "c99") || - !strcmp (arg, "c9x") || - !strcmp (arg, "iso9899:1999") || - !strcmp (arg, "iso9899:199x")) + else if (!strcmp(arg, "c99") || + !strcmp(arg, "c9x") || + !strcmp(arg, "iso9899:1999") || + !strcmp(arg, "iso9899:199x")) standard = STANDARD_C99; - else if (!strcmp (arg, "gnu89")) + else if (!strcmp(arg, "gnu89")) standard = STANDARD_GNU89; - else if (!strcmp (arg, "gnu99") || !strcmp (arg, "gnu9x")) + else if (!strcmp(arg, "gnu99") || !strcmp(arg, "gnu9x")) standard = STANDARD_GNU99; else if (!strcmp(arg, "c11") || @@ -986,7 +986,7 @@ static char **handle_switch_s(const char *arg, char **next) standard = STANDARD_GNU17; else - die ("Unsupported C dialect"); + die("Unsupported C dialect"); } return next; @@ -995,7 +995,7 @@ static char **handle_switch_s(const char *arg, char **next) static char **handle_switch_U(char *arg, char **next) { const char *name = arg + 1; - add_pre_buffer ("#undef %s\n", name); + add_pre_buffer("#undef %s\n", name); return next; } @@ -1516,7 +1516,7 @@ static struct symbol_list *sparse_file(const char *filename) int fd; struct token *token; - if (strcmp (filename, "-") == 0) { + if (strcmp(filename, "-") == 0) { fd = 0; } else { fd = open(filename, O_RDONLY); From patchwork Sun Jul 5 13:02:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11644389 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 76B9792A for ; Sun, 5 Jul 2020 13:02:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F49620747 for ; Sun, 5 Jul 2020 13:02:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pf/L01Cw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726974AbgGENCi (ORCPT ); Sun, 5 Jul 2020 09:02:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726962AbgGENCh (ORCPT ); Sun, 5 Jul 2020 09:02:37 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 922CBC061794 for ; Sun, 5 Jul 2020 06:02:37 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id dg28so32196802edb.3 for ; Sun, 05 Jul 2020 06:02:37 -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 :mime-version:content-transfer-encoding; bh=+XseKbQnu7OoUmmVAPCmrn7d4GEgGn5BQUHGjqMQRps=; b=pf/L01Cw0mqTxrkfN7cHZl1foQo0tMXhAX3dsAdCigEqGZLnzof1mrjNvnFmPfbBee NZAbpA062rLZ43inak5S9BQyWkKkLhgYL5DkOYntn8w/LG/YA1h1ZscTALswKaRfSr3K l9/WWJ9yqRiD8gaf161JiVbkUZYYrfkTGsFHzLveetQKJWiK9YY1gU84ANB9JtiPZggl 7CZQyIrcRFKpg5qAkXTanp1AiSIdnBKsH0UCrdymqzqDdR9fwaMCNlGSs5etA5ZAIrN0 HcX68at2e/aU83d/vU66MVSgXXiNxJIhk+/pmteDTpLZ0vNahHQut5mTi139slARTW+O 6EHQ== 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:mime-version:content-transfer-encoding; bh=+XseKbQnu7OoUmmVAPCmrn7d4GEgGn5BQUHGjqMQRps=; b=RrPtJHTdZ3zaWyY+fq+pIyQN49taxBLB80zmLoxlqlOdLWCvGjrVbdjfCLOxI9OdD5 c44GAVIe3rDL+/bpGbKGqcmzhCyWvAem6tUcg/wulQPbscbNUkY508gYKwy59wpi8+g/ aqvS8pvbKa43Wv2/r86AEBfrfD653xZgPl6lP2wjyl3hw1xugMaQq4pyElJZ6zmPV3P3 MWOKA1G80Vu0qVxeB8FBsKXSuRNkO2G2OH+TugbQKxEgfHdNyTS7Ysq9fIlIgp/ssxZq zk4roY6mXyWD/E/ABaBb9p9dTKRXmLjNTshpvqEk6ep6TpRbz13Uz7ZPCC1hFrXZZPKN taPQ== X-Gm-Message-State: AOAM533I95+QtVKG4rSuCRQzRPhMm+hwEOsvFIOAZ1GMfABuJoX6/y+s CqBRP/RdGcqoA/3Bs3gBjcqpJ86G X-Google-Smtp-Source: ABdhPJwtb9CoI3aNwIpNs8yqJ5KdF6kExLmPfEweLDLDvO3t7F78sFyTblnU7g/H+F6zOVBiYmVKdg== X-Received: by 2002:a05:6402:b99:: with SMTP id cf25mr49011129edb.291.1593954156051; Sun, 05 Jul 2020 06:02:36 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7f9:7600:a542:d3fb:b75a:dec5]) by smtp.gmail.com with ESMTPSA id x16sm19535945edr.52.2020.07.05.06.02.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jul 2020 06:02:35 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 09/15] options: move declaration of tabstop out of "token.h" Date: Sun, 5 Jul 2020 15:02:14 +0200 Message-Id: <20200705130220.26230-10-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> References: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org 'tabstop' is unusual in the sense that it's one the few (the only?) variable defined via an option flag which is not declared in "lib.h" but in "token.h". This for to have to include "token.h" in the code doing the parsing of the options ... Move this declaration to "lib.h". Signed-off-by: Luc Van Oostenryck --- lib.h | 1 + token.h | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/lib.h b/lib.h index 4f67958efdb9..e938f18dfc92 100644 --- a/lib.h +++ b/lib.h @@ -48,6 +48,7 @@ extern int die_if_error; extern int repeat_phase; extern int do_output; extern int gcc_major, gcc_minor, gcc_patchlevel; +extern unsigned int tabstop; extern const char *base_filename; diff --git a/token.h b/token.h index 33a6eda1cc53..c5fdf3d0c879 100644 --- a/token.h +++ b/token.h @@ -64,7 +64,6 @@ struct stream { extern int input_stream_nr; extern struct stream *input_streams; -extern unsigned int tabstop; extern int *hash_stream(const char *name); struct ident { From patchwork Sun Jul 5 13:02:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11644391 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D5FBC13B4 for ; Sun, 5 Jul 2020 13:02:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BE6A620747 for ; Sun, 5 Jul 2020 13:02:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NUjN+fbt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727005AbgGENCj (ORCPT ); Sun, 5 Jul 2020 09:02:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726962AbgGENCj (ORCPT ); Sun, 5 Jul 2020 09:02:39 -0400 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0E4FC061794 for ; Sun, 5 Jul 2020 06:02:38 -0700 (PDT) Received: by mail-ej1-x644.google.com with SMTP id l12so39552924ejn.10 for ; Sun, 05 Jul 2020 06:02:38 -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 :mime-version:content-transfer-encoding; bh=3eElLZDK+73Sru8uMZkWstDbXOPX/1Q4jpihY7SIwDg=; b=NUjN+fbtOw3Vzwvvb5b8v7U/z/U0gvZpQZyeuNSI1p5YCwktTjG8CliMt0f8knhP2H MEgNaIoar6zpeTV12zDLKqG18fwrQwULlGsrWrSMrRcHxeyA6fTwZeWygbdR5mRjsAAK 9Nb1ECeyd+T40+BuoSyoMpC0jQCgMXDMATeC+dVt6aplUkGAszBmmbDvr207cYnbqztY /Fn+hxoL6I2SVQ/vCqRIpYw1/sPcv2feJnW6cOyboqkd/KEjuypDOy9JOWOjgYI2Kub0 9wAZ1/rMvRf02wu7ofhsgWwFFWxV/esBs7RBvdiCNzO3tZ02QNUancBHDxXUTd52vbov lPsA== 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:mime-version:content-transfer-encoding; bh=3eElLZDK+73Sru8uMZkWstDbXOPX/1Q4jpihY7SIwDg=; b=EQJRWsRLAGDAp4r/IQxclTT0luS+Dub8yui0vjL1fgPfumT12tE8GPaoImAAU/INM5 D71aCj1LEC70tv3HDC4okfOwYiPbg/IWX5LWOh9Nq981P951vG0WOQxseBqqqSiqBd4T nuYj64gxS6/dW4fZmQec0zkXbBElVzxeX8z8rQvS3a5hTUYXvVe3AFoC9hcYzzshhZWZ GhcwpsrjEz1dGVEnzrx5f2+eneYuTtGbpzQGzNl/xSbBqtI2YbvFrYaGrVzMkaEqJJCK eHjkhkKWhHgXJVBCU79EZIQ0xVf0yO8O5ie09aTemDpwhs/5aQ+M8XleKnBufMLFiDil 3FVQ== X-Gm-Message-State: AOAM5327XuF0qe+SDAvyV/4r7C8tdur9GFJwOoybe9kxlL9xYxWiCYzj 44qKWREydkXBBkiaiU59MzhJt9K8 X-Google-Smtp-Source: ABdhPJz9OqBfdb2+PD1nVqqEamio0OMu/2CUKowOQGCzmKYJ4eivPovqglLQLuWp20NcE1aTOj1ZHg== X-Received: by 2002:a17:906:ecb3:: with SMTP id qh19mr28236569ejb.273.1593954157006; Sun, 05 Jul 2020 06:02:37 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7f9:7600:a542:d3fb:b75a:dec5]) by smtp.gmail.com with ESMTPSA id x16sm19535945edr.52.2020.07.05.06.02.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jul 2020 06:02:36 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 10/15] options: add a small helper: handle_switch_finalize() Date: Sun, 5 Jul 2020 15:02:15 +0200 Message-Id: <20200705130220.26230-11-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> References: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org This is just to isolate the details about which switch need an extra 'finalization' in a separate function in preparation to moving all the parsing code in a separate file. Signed-off-by: Luc Van Oostenryck --- lib.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib.c b/lib.c index b3bacb180cac..a56efcaa64fd 100644 --- a/lib.c +++ b/lib.c @@ -1220,6 +1220,12 @@ static char **handle_switch(char *arg, char **next) return next; } +static void handle_switch_finalize(void) +{ + handle_switch_v_finalize(); + handle_switch_W_finalize(); +} + //////////////////////////////////////////////////////////////////////////////// // Predefines @@ -1576,8 +1582,7 @@ struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list } add_ptr_list(filelist, arg); } - handle_switch_W_finalize(); - handle_switch_v_finalize(); + handle_switch_finalize(); // Redirect stdout if needed if (dump_macro_defs || preprocess_only) From patchwork Sun Jul 5 13:02:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11644393 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3487392A for ; Sun, 5 Jul 2020 13:02:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 001B320747 for ; Sun, 5 Jul 2020 13:02:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lZaxTYGU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727045AbgGENCl (ORCPT ); Sun, 5 Jul 2020 09:02:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726962AbgGENCl (ORCPT ); Sun, 5 Jul 2020 09:02:41 -0400 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76950C061794 for ; Sun, 5 Jul 2020 06:02:40 -0700 (PDT) Received: by mail-ed1-x542.google.com with SMTP id z17so32201043edr.9 for ; Sun, 05 Jul 2020 06:02:40 -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 :mime-version:content-transfer-encoding; bh=mHWaa4w4wYW0CC/aoKfunHzMnNLY+fWEFMWl0aqomxk=; b=lZaxTYGUBiS5qrRcOjGUwMAAGwsF32Q2M5yOy6vM/zmal/Tf0yF5FUf4jT6VG9YcIA FbHRjv7DJsuUUuGILDu8hui1SROn/nLPZC4RghO5Mol8ZHMQOs6MAbtD144wyUXxrxH7 9X8VsZhVTeB5A0YuxRKnxI6eWC9yyFk4bOgSwAINncOa4wWGrPgkqKlDlTwWQEFOWF5g 0RHUp1pDxME5IMbcST3hqAP3GxYGCN785+nkVMOxPfjeOQZBAIF7F6U74gBg5G3dutze VM7TOHY+3uoG5SUPKxlHUOoqTBJLaN4t0VxOazTa286099B2lLP0bWewn8dI/w7a1I2d CIJQ== 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:mime-version:content-transfer-encoding; bh=mHWaa4w4wYW0CC/aoKfunHzMnNLY+fWEFMWl0aqomxk=; b=MrELr81VORmRj5BH8chOvgb8Q/5RWQ1/GgJ67o+z7lwFTATbncrzvV+oZeSWS6qHLt 7zAVnmgAyPCQpYRPuumUxEqgB6++EEGtvs0L5IACRTpouCo1iKtY8QiVZHEwv2JZfvop 6k55Woi7phN228yCrcgjwp8WQ0txHt8w7Akqo8lgw0DFMUEbb+82i3DDSEk25REEOr4B itUBenE44ubeWFbF1Ed8wynVji3QlVBqVmvS31CLbktCQc3rJY2mjD4e5va2MrvlCRb6 0+Glu51gqCLks0iTRx+NgN+gAw5g63Vk7OI7lo+4Obiz22knjCN+Ls0k0c5BMuTsT+gD oKrA== X-Gm-Message-State: AOAM5324JQJX2Z2KEVBSwu2H386DI59T04SP3ryvv+rYMbE2i3N3ttFJ AhXWCQDk/gb6f9tPwvFqgwBYbpUt X-Google-Smtp-Source: ABdhPJzk9znguXRxp9ORJ5fj5AB5ZahiD9KrO7dvm4jlZqWi27spYMcrHES05rl3i2GlRmihkMYEag== X-Received: by 2002:aa7:c54e:: with SMTP id s14mr51004508edr.81.1593954157970; Sun, 05 Jul 2020 06:02:37 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7f9:7600:a542:d3fb:b75a:dec5]) by smtp.gmail.com with ESMTPSA id x16sm19535945edr.52.2020.07.05.06.02.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jul 2020 06:02:37 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 11/15] options: move option parsing in a separate file Date: Sun, 5 Jul 2020 15:02:16 +0200 Message-Id: <20200705130220.26230-12-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> References: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org lib.c contains to much things and is too hard to keep tidy. So, move everything related to option parsing in it's own file. Signed-off-by: Luc Van Oostenryck --- Makefile | 1 + lib.c | 982 +---------------------------------------------------- lib.h | 117 +------ options.c | 998 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ options.h | 132 ++++++++ 5 files changed, 1134 insertions(+), 1096 deletions(-) create mode 100644 options.c create mode 100644 options.h diff --git a/Makefile b/Makefile index a292e42aabf3..dce666d27c41 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,7 @@ LIB_OBJS += liveness.o LIB_OBJS += memops.o LIB_OBJS += opcode.o LIB_OBJS += optimize.o +LIB_OBJS += options.o LIB_OBJS += parse.o LIB_OBJS += pre-process.o LIB_OBJS += ptrlist.o diff --git a/lib.c b/lib.c index a56efcaa64fd..53b107d2d063 100644 --- a/lib.c +++ b/lib.c @@ -49,27 +49,6 @@ #include "version.h" #include "bits.h" -int verbose, optimize_level, optimize_size, preprocessing; -int die_if_error = 0; -int has_error = 0; -int do_output = 1; - -#ifndef __GNUC__ -# define __GNUC__ 2 -# define __GNUC_MINOR__ 95 -# define __GNUC_PATCHLEVEL__ 0 -#endif - -int gcc_major = __GNUC__; -int gcc_minor = __GNUC_MINOR__; -int gcc_patchlevel = __GNUC_PATCHLEVEL__; - -const char *base_filename; - -static const char *diag_prefix = ""; -static const char *gcc_base_dir = GCC_BASE; -static const char *multiarch_dir = MULTIARCH_TRIPLET; -static const char *outfile = NULL; struct token *skip_to(struct token *token, int op) { @@ -143,7 +122,6 @@ static void do_warn(const char *type, struct position pos, const char * fmt, va_ name, pos.line, pos.pos, diag_prefix, type, buffer); } -unsigned int fmax_warnings = 100; static int show_info = 1; void info(struct position pos, const char * fmt, ...) @@ -247,102 +225,11 @@ void die(const char *fmt, ...) exit(1); } +//////////////////////////////////////////////////////////////////////////////// + static struct token *pre_buffer_begin = NULL; static struct token *pre_buffer_end = NULL; -enum flag_type { - FLAG_OFF, - FLAG_ON, - FLAG_FORCE_OFF -}; - -int Waddress = 0; -int Waddress_space = 1; -int Wbitwise = 1; -int Wbitwise_pointer = 0; -int Wcast_from_as = 0; -int Wcast_to_as = 0; -int Wcast_truncate = 1; -int Wconstant_suffix = 0; -int Wconstexpr_not_const = 0; -int Wcontext = 1; -int Wdecl = 1; -int Wdeclarationafterstatement = -1; -int Wdefault_bitfield_sign = 0; -int Wdesignated_init = 1; -int Wdo_while = 0; -int Wimplicit_int = 1; -int Winit_cstring = 0; -int Wint_to_pointer_cast = 1; -int Wenum_mismatch = 1; -int Wexternal_function_has_definition = 1; -int Wmemcpy_max_count = 1; -int Wnewline_eof = 1; -int Wnon_pointer_null = 1; -int Wold_initializer = 1; -int Wold_style_definition = 1; -int Wone_bit_signed_bitfield = 1; -int Woverride_init = 1; -int Woverride_init_all = 0; -int Woverride_init_whole_range = 0; -int Wparen_string = 0; -int Wpedantic = 0; -int Wpointer_arith = 0; -int Wpointer_to_int_cast = 1; -int Wptr_subtraction_blows = 0; -int Wreturn_void = 0; -int Wshadow = 0; -int Wshift_count_negative = 1; -int Wshift_count_overflow = 1; -int Wsizeof_bool = 0; -int Wsparse_error = FLAG_FORCE_OFF; -int Wstrict_prototypes = 1; -int Wtautological_compare = 0; -int Wtransparent_union = 0; -int Wtypesign = 0; -int Wundef = 0; -int Wuninitialized = 1; -int Wuniversal_initializer = 0; -int Wunknown_attribute = 0; -int Wvla = 1; - -int dump_macro_defs = 0; -int dump_macros_only = 0; - -int dbg_compound = 0; -int dbg_dead = 0; -int dbg_domtree = 0; -int dbg_entry = 0; -int dbg_ir = 0; -int dbg_postorder = 0; - -unsigned long fdump_ir; -int fhosted = 1; -int fmem_report = 0; -unsigned long long fmemcpy_max_count = 100000; -unsigned long fpasses = ~0UL; -int fpic = 0; -int fpie = 0; -int fshort_wchar = 0; -int funsigned_char = 0; - -int preprocess_only; - -enum standard standard = STANDARD_GNU89; - -int arch_msize_long = 0; -int arch_m64 = ARCH_M64_DEFAULT; -int arch_big_endian = ARCH_BIG_ENDIAN; -int arch_fp_abi = FP_ABI_NATIVE; -int arch_os = OS_NATIVE; -int arch_cmodel = CMODEL_UNKNOWN; - - -#define CMDLINE_INCLUDE 20 -static int cmdline_include_nr = 0; -static char *cmdline_include[CMDLINE_INCLUDE]; - - void add_pre_buffer(const char *fmt, ...) { va_list args; @@ -361,871 +248,6 @@ void add_pre_buffer(const char *fmt, ...) pre_buffer_end = end; } -//////////////////////////////////////////////////////////////////////////////// -// Helpers for option parsing - -static const char *match_option(const char *arg, const char *prefix) -{ - unsigned int n = strlen(prefix); - if (strncmp(arg, prefix, n) == 0) - return arg + n; - return NULL; -} - - -struct val_map { - const char *name; - int val; -}; - -static int handle_subopt_val(const char *opt, const char *arg, const struct val_map *map, int *flag) -{ - const char *name; - - if (*arg++ != '=') - die("missing argument for option '%s'", opt); - for (;(name = map->name); map++) { - if (strcmp(name, arg) == 0 || strcmp(name, "*") == 0) { - *flag = map->val; - return 1; - } - if (strcmp(name, "?") == 0) - die("invalid argument '%s' in option '%s'", arg, opt); - } - return 0; -} - - -struct mask_map { - const char *name; - unsigned long mask; -}; - -static int apply_mask(unsigned long *val, const char *str, unsigned len, const struct mask_map *map, int neg) -{ - const char *name; - - for (;(name = map->name); map++) { - if (!strncmp(name, str, len) && !name[len]) { - if (neg == 0) - *val |= map->mask; - else - *val &= ~map->mask; - return 0; - } - } - return 1; -} - -static int handle_suboption_mask(const char *arg, const char *opt, const struct mask_map *map, unsigned long *flag) -{ - if (*opt == '\0') { - apply_mask(flag, "", 0, map, 0); - return 1; - } - if (*opt++ != '=') - return 0; - while (1) { - unsigned int len = strcspn(opt, ",+"); - int neg = 0; - if (len == 0) - goto end; - if (!strncmp(opt, "no-", 3)) { - opt += 3; - len -= 3; - neg = 1; - } - if (apply_mask(flag, opt, len, map, neg)) - die("error: wrong option '%.*s' for \'%s\'", len, opt, arg); - -end: - opt += len; - if (*opt++ == '\0') - break; - } - return 1; -} - - -#define OPT_INVERSE 1 -#define OPT_VAL 2 -struct flag { - const char *name; - int *flag; - int (*fun)(const char *arg, const char *opt, const struct flag *, int options); - unsigned long mask; - int val; -}; - -static int handle_switches(const char *ori, const char *opt, const struct flag *flags) -{ - const char *arg = opt; - int val = 1; - - // Prefixe "no-" mean to turn flag off. - if (strncmp(arg, "no-", 3) == 0) { - arg += 3; - val = 0; - } - - for (; flags->name; flags++) { - const char *opt = match_option(arg, flags->name); - int rc; - - if (!opt) - continue; - - if (flags->fun) { - int options = 0; - if (!val) - options |= OPT_INVERSE; - if ((rc = flags->fun(ori, opt, flags, options))) - return rc; - } - - // boolean flag - if (opt[0] == '\0' && flags->flag) { - if (flags->mask & OPT_VAL) - val = flags->val; - if (flags->mask & OPT_INVERSE) - val = !val; - *flags->flag = val; - return 1; - } - } - - // not handled - return 0; -} - -static char **handle_onoff_switch(char *arg, char **next, const struct flag flags[]) -{ - int flag = FLAG_ON; - char *p = arg + 1; - unsigned i; - - // Prefixes "no" and "no-" mean to turn warning off. - if (p[0] == 'n' && p[1] == 'o') { - p += 2; - if (p[0] == '-') - p++; - flag = FLAG_FORCE_OFF; - } - - for (i = 0; flags[i].name; i++) { - if (!strcmp(p,flags[i].name)) { - *flags[i].flag = flag; - return next; - } - } - - // Unknown. - return NULL; -} - -static void handle_onoff_switch_finalize(const struct flag flags[]) -{ - unsigned i; - - for (i = 0; flags[i].name; i++) { - if (*flags[i].flag == FLAG_FORCE_OFF) - *flags[i].flag = FLAG_OFF; - } -} - -static int handle_switch_setval(const char *arg, const char *opt, const struct flag *flag, int options) -{ - *(flag->flag) = flag->mask; - return 1; -} - - -#define OPTNUM_ZERO_IS_INF 1 -#define OPTNUM_UNLIMITED 2 - -#define OPT_NUMERIC(NAME, TYPE, FUNCTION) \ -static int opt_##NAME(const char *arg, const char *opt, TYPE *ptr, int flag) \ -{ \ - char *end; \ - TYPE val; \ - \ - val = FUNCTION(opt, &end, 0); \ - if (*end != '\0' || end == opt) { \ - if ((flag & OPTNUM_UNLIMITED) && !strcmp(opt, "unlimited")) \ - val = ~val; \ - else \ - die("error: wrong argument to \'%s\'", arg); \ - } \ - if ((flag & OPTNUM_ZERO_IS_INF) && val == 0) \ - val = ~val; \ - *ptr = val; \ - return 1; \ -} - -OPT_NUMERIC(ullong, unsigned long long, strtoull) -OPT_NUMERIC(uint, unsigned int, strtoul) - -//////////////////////////////////////////////////////////////////////////////// -// Option parsing - -static char **handle_switch_a(char *arg, char **next) -{ - if (!strcmp(arg, "ansi")) - standard = STANDARD_C89; - - return next; -} - -static char **handle_switch_D(char *arg, char **next) -{ - const char *name = arg + 1; - const char *value = "1"; - - if (!*name) { - arg = *++next; - if (!arg) - die("argument to `-D' is missing"); - name = arg; - } - - for (;;arg++) { - char c; - c = *arg; - if (!c) - break; - if (c == '=') { - *arg = '\0'; - value = arg + 1; - break; - } - } - add_pre_buffer("#define %s %s\n", name, value); - return next; -} - -static char **handle_switch_d(char *arg, char **next) -{ - char *arg_char = arg + 1; - - /* - * -d, where is a sequence of characters, not preceded - * by a space. If you specify characters whose behaviour conflicts, - * the result is undefined. - */ - while (*arg_char) { - switch (*arg_char) { - case 'M': /* dump just the macro definitions */ - dump_macros_only = 1; - dump_macro_defs = 0; - break; - case 'D': /* like 'M', but also output pre-processed text */ - dump_macro_defs = 1; - dump_macros_only = 0; - break; - case 'N': /* like 'D', but only output macro names not bodies */ - break; - case 'I': /* like 'D', but also output #include directives */ - break; - case 'U': /* like 'D', but only output expanded macros */ - break; - } - arg_char++; - } - return next; -} - -static char **handle_switch_E(char *arg, char **next) -{ - if (arg[1] == '\0') - preprocess_only = 1; - return next; -} - -static int handle_ftabstop(const char *arg, const char *opt, const struct flag *flag, int options) -{ - unsigned long val; - char *end; - - if (*opt == '\0') - die("error: missing argument to \"%s\"", arg); - - /* we silently ignore silly values */ - val = strtoul(opt, &end, 10); - if (*end == '\0' && 1 <= val && val <= 100) - tabstop = val; - - return 1; -} - -static int handle_fpasses(const char *arg, const char *opt, const struct flag *flag, int options) -{ - unsigned long mask; - - mask = flag->mask; - if (*opt == '\0') { - if (options & OPT_INVERSE) - fpasses &= ~mask; - else - fpasses |= mask; - return 1; - } - if (options & OPT_INVERSE) - return 0; - if (!strcmp(opt, "-enable")) { - fpasses |= mask; - return 1; - } - if (!strcmp(opt, "-disable")) { - fpasses &= ~mask; - return 1; - } - if (!strcmp(opt, "=last")) { - // clear everything above - mask |= mask - 1; - fpasses &= mask; - return 1; - } - return 0; -} - -static int handle_fdiagnostic_prefix(const char *arg, const char *opt, const struct flag *flag, int options) -{ - switch (*opt) { - case '\0': - diag_prefix = "sparse: "; - return 1; - case '=': - diag_prefix = xasprintf("%s: ", opt+1); - return 1; - default: - return 0; - } -} - -static int handle_fdump_ir(const char *arg, const char *opt, const struct flag *flag, int options) -{ - static const struct mask_map dump_ir_options[] = { - { "", PASS_LINEARIZE }, - { "linearize", PASS_LINEARIZE }, - { "mem2reg", PASS_MEM2REG }, - { "final", PASS_FINAL }, - { }, - }; - - return handle_suboption_mask(arg, opt, dump_ir_options, &fdump_ir); -} - -static int handle_fmemcpy_max_count(const char *arg, const char *opt, const struct flag *flag, int options) -{ - opt_ullong(arg, opt, &fmemcpy_max_count, OPTNUM_ZERO_IS_INF|OPTNUM_UNLIMITED); - return 1; -} - -static int handle_fmax_warnings(const char *arg, const char *opt, const struct flag *flag, int options) -{ - opt_uint(arg, opt, &fmax_warnings, OPTNUM_UNLIMITED); - return 1; -} - -static struct flag fflags[] = { - { "diagnostic-prefix", NULL, handle_fdiagnostic_prefix }, - { "dump-ir", NULL, handle_fdump_ir }, - { "freestanding", &fhosted, NULL, OPT_INVERSE }, - { "hosted", &fhosted }, - { "linearize", NULL, handle_fpasses, PASS_LINEARIZE }, - { "max-warnings=", NULL, handle_fmax_warnings }, - { "mem-report", &fmem_report }, - { "memcpy-max-count=", NULL, handle_fmemcpy_max_count }, - { "tabstop=", NULL, handle_ftabstop }, - { "mem2reg", NULL, handle_fpasses, PASS_MEM2REG }, - { "optim", NULL, handle_fpasses, PASS_OPTIM }, - { "pic", &fpic, handle_switch_setval, 1 }, - { "PIC", &fpic, handle_switch_setval, 2 }, - { "pie", &fpie, handle_switch_setval, 1 }, - { "PIE", &fpie, handle_switch_setval, 2 }, - { "signed-char", &funsigned_char, NULL, OPT_INVERSE }, - { "short-wchar", &fshort_wchar }, - { "unsigned-char", &funsigned_char, NULL, }, - { }, -}; - -static char **handle_switch_f(char *arg, char **next) -{ - if (handle_switches(arg-1, arg+1, fflags)) - return next; - - return next; -} - -static char **handle_switch_G(char *arg, char **next) -{ - if (!strcmp(arg, "G") && *next) - return next + 1; // "-G 0" - else - return next; // "-G0" or (bogus) terminal "-G" -} - -static char **handle_base_dir(char *arg, char **next) -{ - gcc_base_dir = *++next; - if (!gcc_base_dir) - die("missing argument for -gcc-base-dir option"); - return next; -} - -static char **handle_switch_g(char *arg, char **next) -{ - if (!strcmp(arg, "gcc-base-dir")) - return handle_base_dir(arg, next); - - return next; -} - -static char **handle_switch_I(char *arg, char **next) -{ - char *path = arg+1; - - switch (arg[1]) { - case '-': - add_pre_buffer("#split_include\n"); - break; - - case '\0': /* Plain "-I" */ - path = *++next; - if (!path) - die("missing argument for -I option"); - /* Fall through */ - default: - add_pre_buffer("#add_include \"%s/\"\n", path); - } - return next; -} - -static void add_cmdline_include(char *filename) -{ - if (cmdline_include_nr >= CMDLINE_INCLUDE) - die("too many include files for %s\n", filename); - cmdline_include[cmdline_include_nr++] = filename; -} - -static char **handle_switch_i(char *arg, char **next) -{ - if (*next && !strcmp(arg, "include")) - add_cmdline_include(*++next); - else if (*next && !strcmp(arg, "imacros")) - add_cmdline_include(*++next); - else if (*next && !strcmp(arg, "isystem")) { - char *path = *++next; - if (!path) - die("missing argument for -isystem option"); - add_pre_buffer("#add_isystem \"%s/\"\n", path); - } else if (*next && !strcmp(arg, "idirafter")) { - char *path = *++next; - if (!path) - die("missing argument for -idirafter option"); - add_pre_buffer("#add_dirafter \"%s/\"\n", path); - } - return next; -} - -static char **handle_switch_M(char *arg, char **next) -{ - if (!strcmp(arg, "MF") || !strcmp(arg,"MQ") || !strcmp(arg,"MT")) { - if (!*next) - die("missing argument for -%s option", arg); - return next + 1; - } - return next; -} - -static int handle_mcmodel(const char *opt, const char *arg, const struct flag *flag, int options) -{ - static const struct val_map cmodels[] = { - { "kernel", CMODEL_KERNEL }, - { "large", CMODEL_LARGE }, - { "medany", CMODEL_MEDANY }, - { "medium", CMODEL_MEDIUM }, - { "medlow", CMODEL_MEDLOW }, - { "small", CMODEL_SMALL }, - { "tiny", CMODEL_TINY }, - { }, - }; - return handle_subopt_val(opt, arg, cmodels, flag->flag); -} - -static int handle_mfloat_abi(const char *opt, const char *arg, const struct flag *flag, int options) { - static const struct val_map fp_abis[] = { - { "hard", FP_ABI_HARD }, - { "soft", FP_ABI_SOFT }, - { "softfp", FP_ABI_HYBRID }, - { "?" }, - }; - return handle_subopt_val(opt, arg, fp_abis, flag->flag); -} - -static char **handle_multiarch_dir(char *arg, char **next) -{ - multiarch_dir = *++next; - if (!multiarch_dir) - die("missing argument for -multiarch-dir option"); - return next; -} - -static const struct flag mflags[] = { - { "64", &arch_m64, NULL, OPT_VAL, ARCH_LP64 }, - { "32", &arch_m64, NULL, OPT_VAL, ARCH_LP32 }, - { "31", &arch_m64, NULL, OPT_VAL, ARCH_LP32 }, - { "16", &arch_m64, NULL, OPT_VAL, ARCH_LP32 }, - { "x32",&arch_m64, NULL, OPT_VAL, ARCH_X32 }, - { "size-llp64", &arch_m64, NULL, OPT_VAL, ARCH_LLP64 }, - { "size-long", &arch_msize_long }, - { "big-endian", &arch_big_endian, NULL }, - { "little-endian", &arch_big_endian, NULL, OPT_INVERSE }, - { "cmodel", &arch_cmodel, handle_mcmodel }, - { "float-abi", &arch_fp_abi, handle_mfloat_abi }, - { "hard-float", &arch_fp_abi, NULL, OPT_VAL, FP_ABI_HARD }, - { "soft-float", &arch_fp_abi, NULL, OPT_VAL, FP_ABI_SOFT }, - { } -}; - -static char **handle_switch_m(char *arg, char **next) -{ - if (!strcmp(arg, "multiarch-dir")) { - return handle_multiarch_dir(arg, next); - } else { - handle_switches(arg-1, arg+1, mflags); - } - - return next; -} - -static char **handle_nostdinc(char *arg, char **next) -{ - add_pre_buffer("#nostdinc\n"); - return next; -} - -static char **handle_switch_n(char *arg, char **next) -{ - if (!strcmp(arg, "nostdinc")) - return handle_nostdinc(arg, next); - - return next; -} - -static char **handle_switch_O(char *arg, char **next) -{ - int level = 1; - if (arg[1] >= '0' && arg[1] <= '9') - level = arg[1] - '0'; - optimize_level = level; - optimize_size = arg[1] == 's'; - return next; -} - -static char **handle_switch_o(char *arg, char **next) -{ - if (!strcmp(arg, "o")) { // "-o foo" - if (!*++next) - die("argument to '-o' is missing"); - outfile = *next; - } - // else "-ofoo" - - return next; -} - -static const struct flag pflags[] = { - { "pedantic", &Wpedantic, NULL, OPT_VAL, FLAG_ON }, - { } -}; - -static char **handle_switch_p(char *arg, char **next) -{ - handle_switches(arg-1, arg, pflags); - return next; -} - -static char **handle_switch_s(const char *arg, char **next) -{ - if ((arg = match_option(arg, "std="))) { - if (!strcmp(arg, "c89") || - !strcmp(arg, "iso9899:1990")) - standard = STANDARD_C89; - - else if (!strcmp(arg, "iso9899:199409")) - standard = STANDARD_C94; - - else if (!strcmp(arg, "c99") || - !strcmp(arg, "c9x") || - !strcmp(arg, "iso9899:1999") || - !strcmp(arg, "iso9899:199x")) - standard = STANDARD_C99; - - else if (!strcmp(arg, "gnu89")) - standard = STANDARD_GNU89; - - else if (!strcmp(arg, "gnu99") || !strcmp(arg, "gnu9x")) - standard = STANDARD_GNU99; - - else if (!strcmp(arg, "c11") || - !strcmp(arg, "c1x") || - !strcmp(arg, "iso9899:2011")) - standard = STANDARD_C11; - - else if (!strcmp(arg, "gnu11")) - standard = STANDARD_GNU11; - - else if (!strcmp(arg, "c17") || - !strcmp(arg, "c18") || - !strcmp(arg, "iso9899:2017") || - !strcmp(arg, "iso9899:2018")) - standard = STANDARD_C17; - else if (!strcmp(arg, "gnu17") || - !strcmp(arg, "gnu18")) - standard = STANDARD_GNU17; - - else - die("Unsupported C dialect"); - } - - return next; -} - -static char **handle_switch_U(char *arg, char **next) -{ - const char *name = arg + 1; - add_pre_buffer("#undef %s\n", name); - return next; -} - -static struct flag debugs[] = { - { "compound", &dbg_compound}, - { "dead", &dbg_dead}, - { "domtree", &dbg_domtree}, - { "entry", &dbg_entry}, - { "ir", &dbg_ir}, - { "postorder", &dbg_postorder}, - { } -}; - -static char **handle_switch_v(char *arg, char **next) -{ - char ** ret = handle_onoff_switch(arg, next, debugs); - if (ret) - return ret; - - // Unknown. - do { - verbose++; - } while (*++arg == 'v'); - return next; -} - -static void handle_switch_v_finalize(void) -{ - handle_onoff_switch_finalize(debugs); -} - -static const struct flag warnings[] = { - { "address", &Waddress }, - { "address-space", &Waddress_space }, - { "bitwise", &Wbitwise }, - { "bitwise-pointer", &Wbitwise_pointer}, - { "cast-from-as", &Wcast_from_as }, - { "cast-to-as", &Wcast_to_as }, - { "cast-truncate", &Wcast_truncate }, - { "constant-suffix", &Wconstant_suffix }, - { "constexpr-not-const", &Wconstexpr_not_const}, - { "context", &Wcontext }, - { "decl", &Wdecl }, - { "declaration-after-statement", &Wdeclarationafterstatement }, - { "default-bitfield-sign", &Wdefault_bitfield_sign }, - { "designated-init", &Wdesignated_init }, - { "do-while", &Wdo_while }, - { "enum-mismatch", &Wenum_mismatch }, - { "external-function-has-definition", &Wexternal_function_has_definition }, - { "implicit-int", &Wimplicit_int }, - { "init-cstring", &Winit_cstring }, - { "int-to-pointer-cast", &Wint_to_pointer_cast }, - { "memcpy-max-count", &Wmemcpy_max_count }, - { "non-pointer-null", &Wnon_pointer_null }, - { "newline-eof", &Wnewline_eof }, - { "old-initializer", &Wold_initializer }, - { "old-style-definition", &Wold_style_definition }, - { "one-bit-signed-bitfield", &Wone_bit_signed_bitfield }, - { "override-init", &Woverride_init }, - { "override-init-all", &Woverride_init_all }, - { "paren-string", &Wparen_string }, - { "pedantic", &Wpedantic }, - { "pointer-to-int-cast", &Wpointer_to_int_cast }, - { "ptr-subtraction-blows", &Wptr_subtraction_blows }, - { "return-void", &Wreturn_void }, - { "shadow", &Wshadow }, - { "shift-count-negative", &Wshift_count_negative }, - { "shift-count-overflow", &Wshift_count_overflow }, - { "sizeof-bool", &Wsizeof_bool }, - { "strict-prototypes", &Wstrict_prototypes }, - { "pointer-arith", &Wpointer_arith }, - { "sparse-error", &Wsparse_error }, - { "tautological-compare", &Wtautological_compare }, - { "transparent-union", &Wtransparent_union }, - { "typesign", &Wtypesign }, - { "undef", &Wundef }, - { "uninitialized", &Wuninitialized }, - { "universal-initializer", &Wuniversal_initializer }, - { "unknown-attribute", &Wunknown_attribute }, - { "vla", &Wvla }, - { } -}; - -static char **handle_switch_W(char *arg, char **next) -{ - char ** ret = handle_onoff_switch(arg, next, warnings); - if (ret) - return ret; - - if (!strcmp(arg, "Wsparse-all")) { - int i; - for (i = 0; warnings[i].name; i++) { - if (*warnings[i].flag != FLAG_FORCE_OFF) - *warnings[i].flag = FLAG_ON; - } - } - - // Unknown. - return next; -} - -static void handle_switch_W_finalize(void) -{ - handle_onoff_switch_finalize(warnings); - - /* default Wdeclarationafterstatement based on the C dialect */ - if (-1 == Wdeclarationafterstatement) { - switch (standard) { - case STANDARD_C89: - case STANDARD_C94: - Wdeclarationafterstatement = 1; - break; - default: - Wdeclarationafterstatement = 0; - break; - } - } -} - -static char **handle_switch_x(char *arg, char **next) -{ - if (!*++next) - die("missing argument for -x option"); - return next; -} - - -static char **handle_arch(char *arg, char **next) -{ - enum machine mach; - - if (*arg++ != '=') - die("missing argument for --arch option"); - - mach = target_parse(arg); - if (mach != MACH_UNKNOWN) - target_config(mach); - - return next; -} - -static char **handle_param(char *arg, char **next) -{ - char *value = NULL; - - /* For now just skip any '--param=*' or '--param *' */ - if (*arg == '\0') { - value = *++next; - } else if (isspace((unsigned char)*arg) || *arg == '=') { - value = ++arg; - } - - if (!value) - die("missing argument for --param option"); - - return next; -} - -static char **handle_version(char *arg, char **next) -{ - printf("%s\n", SPARSE_VERSION); - exit(0); -} - -struct switches { - const char *name; - char **(*fn)(char *, char **); - unsigned int prefix:1; -}; - -static char **handle_long_options(char *arg, char **next) -{ - static struct switches cmd[] = { - { "arch", handle_arch, 1 }, - { "param", handle_param, 1 }, - { "version", handle_version }, - { NULL, NULL } - }; - struct switches *s = cmd; - - while (s->name) { - int optlen = strlen(s->name); - if (!strncmp(s->name, arg, optlen + !s->prefix)) - return s->fn(arg + optlen, next); - s++; - } - return next; -} - -static char **handle_switch(char *arg, char **next) -{ - switch (*arg) { - case 'a': return handle_switch_a(arg, next); - case 'D': return handle_switch_D(arg, next); - case 'd': return handle_switch_d(arg, next); - case 'E': return handle_switch_E(arg, next); - case 'f': return handle_switch_f(arg, next); - case 'g': return handle_switch_g(arg, next); - case 'G': return handle_switch_G(arg, next); - case 'I': return handle_switch_I(arg, next); - case 'i': return handle_switch_i(arg, next); - case 'M': return handle_switch_M(arg, next); - case 'm': return handle_switch_m(arg, next); - case 'n': return handle_switch_n(arg, next); - case 'o': return handle_switch_o(arg, next); - case 'O': return handle_switch_O(arg, next); - case 'p': return handle_switch_p(arg, next); - case 's': return handle_switch_s(arg, next); - case 'U': return handle_switch_U(arg, next); - case 'v': return handle_switch_v(arg, next); - case 'W': return handle_switch_W(arg, next); - case 'x': return handle_switch_x(arg, next); - case '-': return handle_long_options(arg + 1, next); - default: - break; - } - - /* - * Ignore unknown command line options: - * they're probably gcc switches - */ - return next; -} - -static void handle_switch_finalize(void) -{ - handle_switch_v_finalize(); - handle_switch_W_finalize(); -} - //////////////////////////////////////////////////////////////////////////////// // Predefines diff --git a/lib.h b/lib.h index e938f18dfc92..b47505f638b4 100644 --- a/lib.h +++ b/lib.h @@ -35,6 +35,7 @@ #include "ptrlist.h" #include "utils.h" #include "bits.h" +#include "options.h" #define DO_STRINGIFY(x) #x #define STRINGIFY(x) DO_STRINGIFY(x) @@ -43,14 +44,6 @@ #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) #endif -extern int verbose, optimize_level, optimize_size, preprocessing; -extern int die_if_error; -extern int repeat_phase; -extern int do_output; -extern int gcc_major, gcc_minor, gcc_patchlevel; -extern unsigned int tabstop; - -extern const char *base_filename; extern unsigned int hexval(unsigned int c); @@ -138,114 +131,6 @@ extern void add_pre_buffer(const char *fmt, ...) FORMAT_ATTR(1); extern void predefine(const char *name, int weak, const char *fmt, ...) FORMAT_ATTR(3); extern void predefine_nostd(const char *name); -extern int preprocess_only; - -extern int Waddress; -extern int Waddress_space; -extern int Wbitwise; -extern int Wbitwise_pointer; -extern int Wcast_from_as; -extern int Wcast_to_as; -extern int Wcast_truncate; -extern int Wconstant_suffix; -extern int Wconstexpr_not_const; -extern int Wcontext; -extern int Wdecl; -extern int Wdeclarationafterstatement; -extern int Wdefault_bitfield_sign; -extern int Wdesignated_init; -extern int Wdo_while; -extern int Wenum_mismatch; -extern int Wexternal_function_has_definition; -extern int Wsparse_error; -extern int Wimplicit_int; -extern int Winit_cstring; -extern int Wint_to_pointer_cast; -extern int Wmemcpy_max_count; -extern int Wnewline_eof; -extern int Wnon_pointer_null; -extern int Wold_initializer; -extern int Wold_style_definition; -extern int Wone_bit_signed_bitfield; -extern int Woverride_init; -extern int Woverride_init_all; -extern int Woverride_init_whole_range; -extern int Wparen_string; -extern int Wpedantic; -extern int Wpointer_arith; -extern int Wpointer_to_int_cast; -extern int Wptr_subtraction_blows; -extern int Wreturn_void; -extern int Wshadow; -extern int Wshift_count_negative; -extern int Wshift_count_overflow; -extern int Wsizeof_bool; -extern int Wstrict_prototypes; -extern int Wtautological_compare; -extern int Wtransparent_union; -extern int Wtypesign; -extern int Wundef; -extern int Wuninitialized; -extern int Wuniversal_initializer; -extern int Wunknown_attribute; -extern int Wvla; - -extern int dump_macro_defs; -extern int dump_macros_only; - -extern int dbg_compound; -extern int dbg_dead; -extern int dbg_domtree; -extern int dbg_entry; -extern int dbg_ir; -extern int dbg_postorder; - -extern unsigned int fmax_warnings; -extern int fmem_report; -extern unsigned long fdump_ir; -extern int fhosted; -extern unsigned long long fmemcpy_max_count; -extern unsigned long fpasses; -extern int fpic; -extern int fpie; -extern int fshort_wchar; -extern int funsigned_char; - -extern int arch_msize_long; -extern int arch_m64; -extern int arch_big_endian; -extern int arch_fp_abi; -extern int arch_os; - -enum { - CMODEL_UNKNOWN, - CMODEL_KERNEL, - CMODEL_LARGE, - CMODEL_MEDANY, - CMODEL_MEDIUM, - CMODEL_MEDLOW, - CMODEL_PIC, - CMODEL_SMALL, - CMODEL_TINY, - CMODEL_LAST, -}; -extern int arch_cmodel; - -enum standard { - STANDARD_NONE, - STANDARD_GNU, - STANDARD_C89, - STANDARD_GNU89 = STANDARD_C89 | STANDARD_GNU, - STANDARD_C94, - STANDARD_GNU94 = STANDARD_C94 | STANDARD_GNU, - STANDARD_C99, - STANDARD_GNU99 = STANDARD_C99 | STANDARD_GNU, - STANDARD_C11, - STANDARD_GNU11 = STANDARD_C11 | STANDARD_GNU, - STANDARD_C17, - STANDARD_GNU17 = STANDARD_C17 | STANDARD_GNU, -}; -extern enum standard standard; extern void dump_macro_definitions(void); extern struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list **files); diff --git a/options.c b/options.c new file mode 100644 index 000000000000..092c8690d054 --- /dev/null +++ b/options.c @@ -0,0 +1,998 @@ +// SPDX-License-Identifier: MIT +/* + * 'sparse' library helper routines. + * + * Copyright (C) 2003 Transmeta Corp. + * 2003-2004 Linus Torvalds + * 2017-2020 Luc Van Oostenryck + */ + +#include "options.h" +#include "lib.h" +#include "machine.h" +#include "target.h" +#include "version.h" +#include +#include +#include +#include + + +int verbose, optimize_level, optimize_size, preprocessing; +int die_if_error = 0; +int has_error = 0; +int do_output = 1; + +#ifndef __GNUC__ +# define __GNUC__ 2 +# define __GNUC_MINOR__ 95 +# define __GNUC_PATCHLEVEL__ 0 +#endif + +int gcc_major = __GNUC__; +int gcc_minor = __GNUC_MINOR__; +int gcc_patchlevel = __GNUC_PATCHLEVEL__; + +const char *base_filename; +const char *diag_prefix = ""; +const char *gcc_base_dir = GCC_BASE; +const char *multiarch_dir = MULTIARCH_TRIPLET; +const char *outfile = NULL; + +enum flag_type { + FLAG_OFF, + FLAG_ON, + FLAG_FORCE_OFF +}; + +int Waddress = 0; +int Waddress_space = 1; +int Wbitwise = 1; +int Wbitwise_pointer = 0; +int Wcast_from_as = 0; +int Wcast_to_as = 0; +int Wcast_truncate = 1; +int Wconstant_suffix = 0; +int Wconstexpr_not_const = 0; +int Wcontext = 1; +int Wdecl = 1; +int Wdeclarationafterstatement = -1; +int Wdefault_bitfield_sign = 0; +int Wdesignated_init = 1; +int Wdo_while = 0; +int Wimplicit_int = 1; +int Winit_cstring = 0; +int Wint_to_pointer_cast = 1; +int Wenum_mismatch = 1; +int Wexternal_function_has_definition = 1; +int Wmemcpy_max_count = 1; +int Wnewline_eof = 1; +int Wnon_pointer_null = 1; +int Wold_initializer = 1; +int Wold_style_definition = 1; +int Wone_bit_signed_bitfield = 1; +int Woverride_init = 1; +int Woverride_init_all = 0; +int Woverride_init_whole_range = 0; +int Wparen_string = 0; +int Wpedantic = 0; +int Wpointer_arith = 0; +int Wpointer_to_int_cast = 1; +int Wptr_subtraction_blows = 0; +int Wreturn_void = 0; +int Wshadow = 0; +int Wshift_count_negative = 1; +int Wshift_count_overflow = 1; +int Wsizeof_bool = 0; +int Wsparse_error = FLAG_FORCE_OFF; +int Wstrict_prototypes = 1; +int Wtautological_compare = 0; +int Wtransparent_union = 0; +int Wtypesign = 0; +int Wundef = 0; +int Wuninitialized = 1; +int Wuniversal_initializer = 0; +int Wunknown_attribute = 0; +int Wvla = 1; + +int dump_macro_defs = 0; +int dump_macros_only = 0; + +int dbg_compound = 0; +int dbg_dead = 0; +int dbg_domtree = 0; +int dbg_entry = 0; +int dbg_ir = 0; +int dbg_postorder = 0; + +unsigned long fdump_ir; +int fhosted = 1; +unsigned int fmax_warnings = 100; +int fmem_report = 0; +unsigned long long fmemcpy_max_count = 100000; +unsigned long fpasses = ~0UL; +int fpic = 0; +int fpie = 0; +int fshort_wchar = 0; +int funsigned_char = 0; + +int preprocess_only; + +enum standard standard = STANDARD_GNU89; + +int arch_msize_long = 0; +int arch_m64 = ARCH_M64_DEFAULT; +int arch_big_endian = ARCH_BIG_ENDIAN; +int arch_fp_abi = FP_ABI_NATIVE; +int arch_os = OS_NATIVE; +int arch_cmodel = CMODEL_UNKNOWN; + + +#define CMDLINE_INCLUDE 20 +int cmdline_include_nr = 0; +char *cmdline_include[CMDLINE_INCLUDE]; + +//////////////////////////////////////////////////////////////////////////////// +// Helpers for option parsing + +static const char *match_option(const char *arg, const char *prefix) +{ + unsigned int n = strlen(prefix); + if (strncmp(arg, prefix, n) == 0) + return arg + n; + return NULL; +} + + +struct val_map { + const char *name; + int val; +}; + +static int handle_subopt_val(const char *opt, const char *arg, const struct val_map *map, int *flag) +{ + const char *name; + + if (*arg++ != '=') + die("missing argument for option '%s'", opt); + for (;(name = map->name); map++) { + if (strcmp(name, arg) == 0 || strcmp(name, "*") == 0) { + *flag = map->val; + return 1; + } + if (strcmp(name, "?") == 0) + die("invalid argument '%s' in option '%s'", arg, opt); + } + return 0; +} + + +struct mask_map { + const char *name; + unsigned long mask; +}; + +static int apply_mask(unsigned long *val, const char *str, unsigned len, const struct mask_map *map, int neg) +{ + const char *name; + + for (;(name = map->name); map++) { + if (!strncmp(name, str, len) && !name[len]) { + if (neg == 0) + *val |= map->mask; + else + *val &= ~map->mask; + return 0; + } + } + return 1; +} + +static int handle_suboption_mask(const char *arg, const char *opt, const struct mask_map *map, unsigned long *flag) +{ + if (*opt == '\0') { + apply_mask(flag, "", 0, map, 0); + return 1; + } + if (*opt++ != '=') + return 0; + while (1) { + unsigned int len = strcspn(opt, ",+"); + int neg = 0; + if (len == 0) + goto end; + if (!strncmp(opt, "no-", 3)) { + opt += 3; + len -= 3; + neg = 1; + } + if (apply_mask(flag, opt, len, map, neg)) + die("error: wrong option '%.*s' for \'%s\'", len, opt, arg); + +end: + opt += len; + if (*opt++ == '\0') + break; + } + return 1; +} + + +#define OPT_INVERSE 1 +#define OPT_VAL 2 +struct flag { + const char *name; + int *flag; + int (*fun)(const char *arg, const char *opt, const struct flag *, int options); + unsigned long mask; + int val; +}; + +static int handle_switches(const char *ori, const char *opt, const struct flag *flags) +{ + const char *arg = opt; + int val = 1; + + // Prefixe "no-" mean to turn flag off. + if (strncmp(arg, "no-", 3) == 0) { + arg += 3; + val = 0; + } + + for (; flags->name; flags++) { + const char *opt = match_option(arg, flags->name); + int rc; + + if (!opt) + continue; + + if (flags->fun) { + int options = 0; + if (!val) + options |= OPT_INVERSE; + if ((rc = flags->fun(ori, opt, flags, options))) + return rc; + } + + // boolean flag + if (opt[0] == '\0' && flags->flag) { + if (flags->mask & OPT_VAL) + val = flags->val; + if (flags->mask & OPT_INVERSE) + val = !val; + *flags->flag = val; + return 1; + } + } + + // not handled + return 0; +} + +static char **handle_onoff_switch(char *arg, char **next, const struct flag flags[]) +{ + int flag = FLAG_ON; + char *p = arg + 1; + unsigned i; + + // Prefixes "no" and "no-" mean to turn warning off. + if (p[0] == 'n' && p[1] == 'o') { + p += 2; + if (p[0] == '-') + p++; + flag = FLAG_FORCE_OFF; + } + + for (i = 0; flags[i].name; i++) { + if (!strcmp(p,flags[i].name)) { + *flags[i].flag = flag; + return next; + } + } + + // Unknown. + return NULL; +} + +static void handle_onoff_switch_finalize(const struct flag flags[]) +{ + unsigned i; + + for (i = 0; flags[i].name; i++) { + if (*flags[i].flag == FLAG_FORCE_OFF) + *flags[i].flag = FLAG_OFF; + } +} + +static int handle_switch_setval(const char *arg, const char *opt, const struct flag *flag, int options) +{ + *(flag->flag) = flag->mask; + return 1; +} + + +#define OPTNUM_ZERO_IS_INF 1 +#define OPTNUM_UNLIMITED 2 + +#define OPT_NUMERIC(NAME, TYPE, FUNCTION) \ +static int opt_##NAME(const char *arg, const char *opt, TYPE *ptr, int flag) \ +{ \ + char *end; \ + TYPE val; \ + \ + val = FUNCTION(opt, &end, 0); \ + if (*end != '\0' || end == opt) { \ + if ((flag & OPTNUM_UNLIMITED) && !strcmp(opt, "unlimited")) \ + val = ~val; \ + else \ + die("error: wrong argument to \'%s\'", arg); \ + } \ + if ((flag & OPTNUM_ZERO_IS_INF) && val == 0) \ + val = ~val; \ + *ptr = val; \ + return 1; \ +} + +OPT_NUMERIC(ullong, unsigned long long, strtoull) +OPT_NUMERIC(uint, unsigned int, strtoul) + +//////////////////////////////////////////////////////////////////////////////// +// Option parsing + +static char **handle_switch_a(char *arg, char **next) +{ + if (!strcmp(arg, "ansi")) + standard = STANDARD_C89; + + return next; +} + +static char **handle_switch_D(char *arg, char **next) +{ + const char *name = arg + 1; + const char *value = "1"; + + if (!*name) { + arg = *++next; + if (!arg) + die("argument to `-D' is missing"); + name = arg; + } + + for (;;arg++) { + char c; + c = *arg; + if (!c) + break; + if (c == '=') { + *arg = '\0'; + value = arg + 1; + break; + } + } + add_pre_buffer("#define %s %s\n", name, value); + return next; +} + +static char **handle_switch_d(char *arg, char **next) +{ + char *arg_char = arg + 1; + + /* + * -d, where is a sequence of characters, not preceded + * by a space. If you specify characters whose behaviour conflicts, + * the result is undefined. + */ + while (*arg_char) { + switch (*arg_char) { + case 'M': /* dump just the macro definitions */ + dump_macros_only = 1; + dump_macro_defs = 0; + break; + case 'D': /* like 'M', but also output pre-processed text */ + dump_macro_defs = 1; + dump_macros_only = 0; + break; + case 'N': /* like 'D', but only output macro names not bodies */ + break; + case 'I': /* like 'D', but also output #include directives */ + break; + case 'U': /* like 'D', but only output expanded macros */ + break; + } + arg_char++; + } + return next; +} + +static char **handle_switch_E(char *arg, char **next) +{ + if (arg[1] == '\0') + preprocess_only = 1; + return next; +} + +static int handle_ftabstop(const char *arg, const char *opt, const struct flag *flag, int options) +{ + unsigned long val; + char *end; + + if (*opt == '\0') + die("error: missing argument to \"%s\"", arg); + + /* we silently ignore silly values */ + val = strtoul(opt, &end, 10); + if (*end == '\0' && 1 <= val && val <= 100) + tabstop = val; + + return 1; +} + +static int handle_fpasses(const char *arg, const char *opt, const struct flag *flag, int options) +{ + unsigned long mask; + + mask = flag->mask; + if (*opt == '\0') { + if (options & OPT_INVERSE) + fpasses &= ~mask; + else + fpasses |= mask; + return 1; + } + if (options & OPT_INVERSE) + return 0; + if (!strcmp(opt, "-enable")) { + fpasses |= mask; + return 1; + } + if (!strcmp(opt, "-disable")) { + fpasses &= ~mask; + return 1; + } + if (!strcmp(opt, "=last")) { + // clear everything above + mask |= mask - 1; + fpasses &= mask; + return 1; + } + return 0; +} + +static int handle_fdiagnostic_prefix(const char *arg, const char *opt, const struct flag *flag, int options) +{ + switch (*opt) { + case '\0': + diag_prefix = "sparse: "; + return 1; + case '=': + diag_prefix = xasprintf("%s: ", opt+1); + return 1; + default: + return 0; + } +} + +static int handle_fdump_ir(const char *arg, const char *opt, const struct flag *flag, int options) +{ + static const struct mask_map dump_ir_options[] = { + { "", PASS_LINEARIZE }, + { "linearize", PASS_LINEARIZE }, + { "mem2reg", PASS_MEM2REG }, + { "final", PASS_FINAL }, + { }, + }; + + return handle_suboption_mask(arg, opt, dump_ir_options, &fdump_ir); +} + +static int handle_fmemcpy_max_count(const char *arg, const char *opt, const struct flag *flag, int options) +{ + opt_ullong(arg, opt, &fmemcpy_max_count, OPTNUM_ZERO_IS_INF|OPTNUM_UNLIMITED); + return 1; +} + +static int handle_fmax_warnings(const char *arg, const char *opt, const struct flag *flag, int options) +{ + opt_uint(arg, opt, &fmax_warnings, OPTNUM_UNLIMITED); + return 1; +} + +static struct flag fflags[] = { + { "diagnostic-prefix", NULL, handle_fdiagnostic_prefix }, + { "dump-ir", NULL, handle_fdump_ir }, + { "freestanding", &fhosted, NULL, OPT_INVERSE }, + { "hosted", &fhosted }, + { "linearize", NULL, handle_fpasses, PASS_LINEARIZE }, + { "max-warnings=", NULL, handle_fmax_warnings }, + { "mem-report", &fmem_report }, + { "memcpy-max-count=", NULL, handle_fmemcpy_max_count }, + { "tabstop=", NULL, handle_ftabstop }, + { "mem2reg", NULL, handle_fpasses, PASS_MEM2REG }, + { "optim", NULL, handle_fpasses, PASS_OPTIM }, + { "pic", &fpic, handle_switch_setval, 1 }, + { "PIC", &fpic, handle_switch_setval, 2 }, + { "pie", &fpie, handle_switch_setval, 1 }, + { "PIE", &fpie, handle_switch_setval, 2 }, + { "signed-char", &funsigned_char, NULL, OPT_INVERSE }, + { "short-wchar", &fshort_wchar }, + { "unsigned-char", &funsigned_char, NULL, }, + { }, +}; + +static char **handle_switch_f(char *arg, char **next) +{ + if (handle_switches(arg-1, arg+1, fflags)) + return next; + + return next; +} + +static char **handle_switch_G(char *arg, char **next) +{ + if (!strcmp(arg, "G") && *next) + return next + 1; // "-G 0" + else + return next; // "-G0" or (bogus) terminal "-G" +} + +static char **handle_base_dir(char *arg, char **next) +{ + gcc_base_dir = *++next; + if (!gcc_base_dir) + die("missing argument for -gcc-base-dir option"); + return next; +} + +static char **handle_switch_g(char *arg, char **next) +{ + if (!strcmp(arg, "gcc-base-dir")) + return handle_base_dir(arg, next); + + return next; +} + +static char **handle_switch_I(char *arg, char **next) +{ + char *path = arg+1; + + switch (arg[1]) { + case '-': + add_pre_buffer("#split_include\n"); + break; + + case '\0': /* Plain "-I" */ + path = *++next; + if (!path) + die("missing argument for -I option"); + /* Fall through */ + default: + add_pre_buffer("#add_include \"%s/\"\n", path); + } + return next; +} + +static void add_cmdline_include(char *filename) +{ + if (cmdline_include_nr >= CMDLINE_INCLUDE) + die("too many include files for %s\n", filename); + cmdline_include[cmdline_include_nr++] = filename; +} + +static char **handle_switch_i(char *arg, char **next) +{ + if (*next && !strcmp(arg, "include")) + add_cmdline_include(*++next); + else if (*next && !strcmp(arg, "imacros")) + add_cmdline_include(*++next); + else if (*next && !strcmp(arg, "isystem")) { + char *path = *++next; + if (!path) + die("missing argument for -isystem option"); + add_pre_buffer("#add_isystem \"%s/\"\n", path); + } else if (*next && !strcmp(arg, "idirafter")) { + char *path = *++next; + if (!path) + die("missing argument for -idirafter option"); + add_pre_buffer("#add_dirafter \"%s/\"\n", path); + } + return next; +} + +static char **handle_switch_M(char *arg, char **next) +{ + if (!strcmp(arg, "MF") || !strcmp(arg,"MQ") || !strcmp(arg,"MT")) { + if (!*next) + die("missing argument for -%s option", arg); + return next + 1; + } + return next; +} + +static int handle_mcmodel(const char *opt, const char *arg, const struct flag *flag, int options) +{ + static const struct val_map cmodels[] = { + { "kernel", CMODEL_KERNEL }, + { "large", CMODEL_LARGE }, + { "medany", CMODEL_MEDANY }, + { "medium", CMODEL_MEDIUM }, + { "medlow", CMODEL_MEDLOW }, + { "small", CMODEL_SMALL }, + { "tiny", CMODEL_TINY }, + { }, + }; + return handle_subopt_val(opt, arg, cmodels, flag->flag); +} + +static int handle_mfloat_abi(const char *opt, const char *arg, const struct flag *flag, int options) { + static const struct val_map fp_abis[] = { + { "hard", FP_ABI_HARD }, + { "soft", FP_ABI_SOFT }, + { "softfp", FP_ABI_HYBRID }, + { "?" }, + }; + return handle_subopt_val(opt, arg, fp_abis, flag->flag); +} + +static char **handle_multiarch_dir(char *arg, char **next) +{ + multiarch_dir = *++next; + if (!multiarch_dir) + die("missing argument for -multiarch-dir option"); + return next; +} + +static const struct flag mflags[] = { + { "64", &arch_m64, NULL, OPT_VAL, ARCH_LP64 }, + { "32", &arch_m64, NULL, OPT_VAL, ARCH_LP32 }, + { "31", &arch_m64, NULL, OPT_VAL, ARCH_LP32 }, + { "16", &arch_m64, NULL, OPT_VAL, ARCH_LP32 }, + { "x32",&arch_m64, NULL, OPT_VAL, ARCH_X32 }, + { "size-llp64", &arch_m64, NULL, OPT_VAL, ARCH_LLP64 }, + { "size-long", &arch_msize_long }, + { "big-endian", &arch_big_endian, NULL }, + { "little-endian", &arch_big_endian, NULL, OPT_INVERSE }, + { "cmodel", &arch_cmodel, handle_mcmodel }, + { "float-abi", &arch_fp_abi, handle_mfloat_abi }, + { "hard-float", &arch_fp_abi, NULL, OPT_VAL, FP_ABI_HARD }, + { "soft-float", &arch_fp_abi, NULL, OPT_VAL, FP_ABI_SOFT }, + { } +}; + +static char **handle_switch_m(char *arg, char **next) +{ + if (!strcmp(arg, "multiarch-dir")) { + return handle_multiarch_dir(arg, next); + } else { + handle_switches(arg-1, arg+1, mflags); + } + + return next; +} + +static char **handle_nostdinc(char *arg, char **next) +{ + add_pre_buffer("#nostdinc\n"); + return next; +} + +static char **handle_switch_n(char *arg, char **next) +{ + if (!strcmp(arg, "nostdinc")) + return handle_nostdinc(arg, next); + + return next; +} + +static char **handle_switch_O(char *arg, char **next) +{ + int level = 1; + if (arg[1] >= '0' && arg[1] <= '9') + level = arg[1] - '0'; + optimize_level = level; + optimize_size = arg[1] == 's'; + return next; +} + +static char **handle_switch_o(char *arg, char **next) +{ + if (!strcmp(arg, "o")) { // "-o foo" + if (!*++next) + die("argument to '-o' is missing"); + outfile = *next; + } + // else "-ofoo" + + return next; +} + +static const struct flag pflags[] = { + { "pedantic", &Wpedantic, NULL, OPT_VAL, FLAG_ON }, + { } +}; + +static char **handle_switch_p(char *arg, char **next) +{ + handle_switches(arg-1, arg, pflags); + return next; +} + +static char **handle_switch_s(const char *arg, char **next) +{ + if ((arg = match_option(arg, "std="))) { + if (!strcmp(arg, "c89") || + !strcmp(arg, "iso9899:1990")) + standard = STANDARD_C89; + + else if (!strcmp(arg, "iso9899:199409")) + standard = STANDARD_C94; + + else if (!strcmp(arg, "c99") || + !strcmp(arg, "c9x") || + !strcmp(arg, "iso9899:1999") || + !strcmp(arg, "iso9899:199x")) + standard = STANDARD_C99; + + else if (!strcmp(arg, "gnu89")) + standard = STANDARD_GNU89; + + else if (!strcmp(arg, "gnu99") || !strcmp(arg, "gnu9x")) + standard = STANDARD_GNU99; + + else if (!strcmp(arg, "c11") || + !strcmp(arg, "c1x") || + !strcmp(arg, "iso9899:2011")) + standard = STANDARD_C11; + + else if (!strcmp(arg, "gnu11")) + standard = STANDARD_GNU11; + + else if (!strcmp(arg, "c17") || + !strcmp(arg, "c18") || + !strcmp(arg, "iso9899:2017") || + !strcmp(arg, "iso9899:2018")) + standard = STANDARD_C17; + else if (!strcmp(arg, "gnu17") || + !strcmp(arg, "gnu18")) + standard = STANDARD_GNU17; + + else + die("Unsupported C dialect"); + } + + return next; +} + +static char **handle_switch_U(char *arg, char **next) +{ + const char *name = arg + 1; + add_pre_buffer("#undef %s\n", name); + return next; +} + +static struct flag debugs[] = { + { "compound", &dbg_compound}, + { "dead", &dbg_dead}, + { "domtree", &dbg_domtree}, + { "entry", &dbg_entry}, + { "ir", &dbg_ir}, + { "postorder", &dbg_postorder}, + { } +}; + +static char **handle_switch_v(char *arg, char **next) +{ + char ** ret = handle_onoff_switch(arg, next, debugs); + if (ret) + return ret; + + // Unknown. + do { + verbose++; + } while (*++arg == 'v'); + return next; +} + +static void handle_switch_v_finalize(void) +{ + handle_onoff_switch_finalize(debugs); +} + +static const struct flag warnings[] = { + { "address", &Waddress }, + { "address-space", &Waddress_space }, + { "bitwise", &Wbitwise }, + { "bitwise-pointer", &Wbitwise_pointer}, + { "cast-from-as", &Wcast_from_as }, + { "cast-to-as", &Wcast_to_as }, + { "cast-truncate", &Wcast_truncate }, + { "constant-suffix", &Wconstant_suffix }, + { "constexpr-not-const", &Wconstexpr_not_const}, + { "context", &Wcontext }, + { "decl", &Wdecl }, + { "declaration-after-statement", &Wdeclarationafterstatement }, + { "default-bitfield-sign", &Wdefault_bitfield_sign }, + { "designated-init", &Wdesignated_init }, + { "do-while", &Wdo_while }, + { "enum-mismatch", &Wenum_mismatch }, + { "external-function-has-definition", &Wexternal_function_has_definition }, + { "implicit-int", &Wimplicit_int }, + { "init-cstring", &Winit_cstring }, + { "int-to-pointer-cast", &Wint_to_pointer_cast }, + { "memcpy-max-count", &Wmemcpy_max_count }, + { "non-pointer-null", &Wnon_pointer_null }, + { "newline-eof", &Wnewline_eof }, + { "old-initializer", &Wold_initializer }, + { "old-style-definition", &Wold_style_definition }, + { "one-bit-signed-bitfield", &Wone_bit_signed_bitfield }, + { "override-init", &Woverride_init }, + { "override-init-all", &Woverride_init_all }, + { "paren-string", &Wparen_string }, + { "pedantic", &Wpedantic }, + { "pointer-to-int-cast", &Wpointer_to_int_cast }, + { "ptr-subtraction-blows", &Wptr_subtraction_blows }, + { "return-void", &Wreturn_void }, + { "shadow", &Wshadow }, + { "shift-count-negative", &Wshift_count_negative }, + { "shift-count-overflow", &Wshift_count_overflow }, + { "sizeof-bool", &Wsizeof_bool }, + { "strict-prototypes", &Wstrict_prototypes }, + { "pointer-arith", &Wpointer_arith }, + { "sparse-error", &Wsparse_error }, + { "tautological-compare", &Wtautological_compare }, + { "transparent-union", &Wtransparent_union }, + { "typesign", &Wtypesign }, + { "undef", &Wundef }, + { "uninitialized", &Wuninitialized }, + { "universal-initializer", &Wuniversal_initializer }, + { "unknown-attribute", &Wunknown_attribute }, + { "vla", &Wvla }, + { } +}; + +static char **handle_switch_W(char *arg, char **next) +{ + char ** ret = handle_onoff_switch(arg, next, warnings); + if (ret) + return ret; + + if (!strcmp(arg, "Wsparse-all")) { + int i; + for (i = 0; warnings[i].name; i++) { + if (*warnings[i].flag != FLAG_FORCE_OFF) + *warnings[i].flag = FLAG_ON; + } + } + + // Unknown. + return next; +} + +static void handle_switch_W_finalize(void) +{ + handle_onoff_switch_finalize(warnings); + + /* default Wdeclarationafterstatement based on the C dialect */ + if (-1 == Wdeclarationafterstatement) { + switch (standard) { + case STANDARD_C89: + case STANDARD_C94: + Wdeclarationafterstatement = 1; + break; + default: + Wdeclarationafterstatement = 0; + break; + } + } +} + +static char **handle_switch_x(char *arg, char **next) +{ + if (!*++next) + die("missing argument for -x option"); + return next; +} + + +static char **handle_arch(char *arg, char **next) +{ + enum machine mach; + + if (*arg++ != '=') + die("missing argument for --arch option"); + + mach = target_parse(arg); + if (mach != MACH_UNKNOWN) + target_config(mach); + + return next; +} + +static char **handle_param(char *arg, char **next) +{ + char *value = NULL; + + /* For now just skip any '--param=*' or '--param *' */ + if (*arg == '\0') { + value = *++next; + } else if (isspace((unsigned char)*arg) || *arg == '=') { + value = ++arg; + } + + if (!value) + die("missing argument for --param option"); + + return next; +} + +static char **handle_version(char *arg, char **next) +{ + printf("%s\n", SPARSE_VERSION); + exit(0); +} + +struct switches { + const char *name; + char **(*fn)(char *, char **); + unsigned int prefix:1; +}; + +static char **handle_long_options(char *arg, char **next) +{ + static struct switches cmd[] = { + { "arch", handle_arch, 1 }, + { "param", handle_param, 1 }, + { "version", handle_version }, + { NULL, NULL } + }; + struct switches *s = cmd; + + while (s->name) { + int optlen = strlen(s->name); + if (!strncmp(s->name, arg, optlen + !s->prefix)) + return s->fn(arg + optlen, next); + s++; + } + return next; +} + +char **handle_switch(char *arg, char **next) +{ + switch (*arg) { + case 'a': return handle_switch_a(arg, next); + case 'D': return handle_switch_D(arg, next); + case 'd': return handle_switch_d(arg, next); + case 'E': return handle_switch_E(arg, next); + case 'f': return handle_switch_f(arg, next); + case 'g': return handle_switch_g(arg, next); + case 'G': return handle_switch_G(arg, next); + case 'I': return handle_switch_I(arg, next); + case 'i': return handle_switch_i(arg, next); + case 'M': return handle_switch_M(arg, next); + case 'm': return handle_switch_m(arg, next); + case 'n': return handle_switch_n(arg, next); + case 'o': return handle_switch_o(arg, next); + case 'O': return handle_switch_O(arg, next); + case 'p': return handle_switch_p(arg, next); + case 's': return handle_switch_s(arg, next); + case 'U': return handle_switch_U(arg, next); + case 'v': return handle_switch_v(arg, next); + case 'W': return handle_switch_W(arg, next); + case 'x': return handle_switch_x(arg, next); + case '-': return handle_long_options(arg + 1, next); + default: + break; + } + + /* + * Ignore unknown command line options: + * they're probably gcc switches + */ + return next; +} + +void handle_switch_finalize(void) +{ + handle_switch_v_finalize(); + handle_switch_W_finalize(); +} diff --git a/options.h b/options.h new file mode 100644 index 000000000000..52d1106e7576 --- /dev/null +++ b/options.h @@ -0,0 +1,132 @@ +#ifndef OPTIONS_H +#define OPTIONS_H + +extern int verbose, optimize_level, optimize_size, preprocessing; +extern int die_if_error; +extern int repeat_phase; +extern int do_output; +extern int gcc_major, gcc_minor, gcc_patchlevel; +extern unsigned int tabstop; + +extern const char *base_filename; +extern const char *diag_prefix; +extern const char *gcc_base_dir; +extern const char *multiarch_dir; +extern const char *outfile; +extern int cmdline_include_nr; +extern char *cmdline_include[]; + +extern char **handle_switch(char *arg, char **next); +extern void handle_switch_finalize(void); + + +extern int preprocess_only; + +extern int Waddress; +extern int Waddress_space; +extern int Wbitwise; +extern int Wbitwise_pointer; +extern int Wcast_from_as; +extern int Wcast_to_as; +extern int Wcast_truncate; +extern int Wconstant_suffix; +extern int Wconstexpr_not_const; +extern int Wcontext; +extern int Wdecl; +extern int Wdeclarationafterstatement; +extern int Wdefault_bitfield_sign; +extern int Wdesignated_init; +extern int Wdo_while; +extern int Wenum_mismatch; +extern int Wexternal_function_has_definition; +extern int Wsparse_error; +extern int Wimplicit_int; +extern int Winit_cstring; +extern int Wint_to_pointer_cast; +extern int Wmemcpy_max_count; +extern int Wnewline_eof; +extern int Wnon_pointer_null; +extern int Wold_initializer; +extern int Wold_style_definition; +extern int Wone_bit_signed_bitfield; +extern int Woverride_init; +extern int Woverride_init_all; +extern int Woverride_init_whole_range; +extern int Wparen_string; +extern int Wpedantic; +extern int Wpointer_arith; +extern int Wpointer_to_int_cast; +extern int Wptr_subtraction_blows; +extern int Wreturn_void; +extern int Wshadow; +extern int Wshift_count_negative; +extern int Wshift_count_overflow; +extern int Wsizeof_bool; +extern int Wstrict_prototypes; +extern int Wtautological_compare; +extern int Wtransparent_union; +extern int Wtypesign; +extern int Wundef; +extern int Wuninitialized; +extern int Wuniversal_initializer; +extern int Wunknown_attribute; +extern int Wvla; + +extern int dump_macro_defs; +extern int dump_macros_only; + +extern int dbg_compound; +extern int dbg_dead; +extern int dbg_domtree; +extern int dbg_entry; +extern int dbg_ir; +extern int dbg_postorder; + +extern unsigned int fmax_warnings; +extern int fmem_report; +extern unsigned long fdump_ir; +extern int fhosted; +extern unsigned long long fmemcpy_max_count; +extern unsigned long fpasses; +extern int fpic; +extern int fpie; +extern int fshort_wchar; +extern int funsigned_char; + +extern int arch_msize_long; +extern int arch_m64; +extern int arch_big_endian; +extern int arch_fp_abi; +extern int arch_os; + +enum { + CMODEL_UNKNOWN, + CMODEL_KERNEL, + CMODEL_LARGE, + CMODEL_MEDANY, + CMODEL_MEDIUM, + CMODEL_MEDLOW, + CMODEL_PIC, + CMODEL_SMALL, + CMODEL_TINY, + CMODEL_LAST, +}; +extern int arch_cmodel; + +enum standard { + STANDARD_NONE, + STANDARD_GNU, + STANDARD_C89, + STANDARD_GNU89 = STANDARD_C89 | STANDARD_GNU, + STANDARD_C94, + STANDARD_GNU94 = STANDARD_C94 | STANDARD_GNU, + STANDARD_C99, + STANDARD_GNU99 = STANDARD_C99 | STANDARD_GNU, + STANDARD_C11, + STANDARD_GNU11 = STANDARD_C11 | STANDARD_GNU, + STANDARD_C17, + STANDARD_GNU17 = STANDARD_C17 | STANDARD_GNU, +}; +extern enum standard standard; + +#endif From patchwork Sun Jul 5 13:02:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11644395 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D14AF14DD for ; Sun, 5 Jul 2020 13:02:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B427920747 for ; Sun, 5 Jul 2020 13:02:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qjw/BjfK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726962AbgGENCm (ORCPT ); Sun, 5 Jul 2020 09:02:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727031AbgGENCl (ORCPT ); Sun, 5 Jul 2020 09:02:41 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 069D1C08C5DE for ; Sun, 5 Jul 2020 06:02:41 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id w6so39615457ejq.6 for ; Sun, 05 Jul 2020 06:02:40 -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 :mime-version:content-transfer-encoding; bh=jd5OyA62jQVyFQS+Wq/MjJJlFxvsmVOnF8emDjOOsMo=; b=qjw/BjfKHive2O6RxU8KQoBD5mFQtiYTxfpJw3G3SKtK9kg3mIoEVbDu2pBMi5BVXJ Xuxjjai3ShXdHFBsxWJ5Jd5Sp153TItVhck6BUPZiiULaRj96cvgWR6MfK46e/O9lUe9 FuwUWj/GdmNGxVVMDoPdnt1Z0ajIPFJFDLr1XmBXFtO45+G0pEcTTHKuyEHicsxtCbj6 ySE4kGhltVZsSu9ibIlGCT3OhzRGl4n/jhm3H+/rLqGK0QhpJvNHjbeBaQYD9SN9LFYi WOoTmwOJ/nrmRyCKpGN3bsMa/AW8WFiin8IQSF8fAgMUeQ5NqFe71YXwQaLjoWjY1JkN F8dw== 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:mime-version:content-transfer-encoding; bh=jd5OyA62jQVyFQS+Wq/MjJJlFxvsmVOnF8emDjOOsMo=; b=EbdZdya0fjbExtA9vHrU/8Z/9dDPlAHqH92M4uhrGRK8QxiuTa0PzfNZW+RzrKQqQ+ cK5kygoqvRIM9VaiGEqf6gCY2qTzaAfXYaX9jJ6IwvZCuu0If/T6Uz7yiRM0YV5w3pXQ f5g77rFy6FI+veakcTcUUbXiGa/8MvM6imPqwoHXK5jK85BIG6bz42/8ESut+uPcwKZV wvBRF/Wd0OB/j7DVurYI37UuB6mwcQs4IbOu6d/+/1f1vW6aLjk2dAgDvh2yWWltELYz qMuWFQooktuaedBVyV7qVT+kRbPt5lmdKncQfpQarUglJP2jGuDkCJSG2QHxYKalPorP HviQ== X-Gm-Message-State: AOAM533QEXd7BytDWVwg/YyybtoqVXHn3JT0jxgQtDEVwOx3XXfH3iYL 08GdJejvGro5N7hf7oy2Rl1t7qnh X-Google-Smtp-Source: ABdhPJygQDVZ6VaZP1txisirL7tbBPSmuVPTHfJElC8LRd3/MCiZPjjmjca4XoCWfuBRqQo7p6oyiw== X-Received: by 2002:a17:906:1986:: with SMTP id g6mr28262640ejd.404.1593954159394; Sun, 05 Jul 2020 06:02:39 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7f9:7600:a542:d3fb:b75a:dec5]) by smtp.gmail.com with ESMTPSA id x16sm19535945edr.52.2020.07.05.06.02.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jul 2020 06:02:38 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 12/15] options: keep the options sorted Date: Sun, 5 Jul 2020 15:02:17 +0200 Message-Id: <20200705130220.26230-13-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> References: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org The declarations and definitions of the variables corresponding to the options half-sorted half-unsorted. Sort them a little more. Signed-off-by: Luc Van Oostenryck --- options.c | 98 +++++++++++++++++++------------------- options.h | 137 ++++++++++++++++++++++++++++-------------------------- 2 files changed, 120 insertions(+), 115 deletions(-) diff --git a/options.c b/options.c index 092c8690d054..9f05bdf9cf4f 100644 --- a/options.c +++ b/options.c @@ -18,20 +18,33 @@ #include -int verbose, optimize_level, optimize_size, preprocessing; -int die_if_error = 0; -int has_error = 0; -int do_output = 1; - #ifndef __GNUC__ # define __GNUC__ 2 # define __GNUC_MINOR__ 95 # define __GNUC_PATCHLEVEL__ 0 #endif +enum flag_type { + FLAG_OFF, + FLAG_ON, + FLAG_FORCE_OFF +}; + +int die_if_error = 0; +int do_output = 1; int gcc_major = __GNUC__; int gcc_minor = __GNUC_MINOR__; int gcc_patchlevel = __GNUC_PATCHLEVEL__; +int has_error = 0; +int optimize_level; +int optimize_size; +int preprocess_only; +int preprocessing; +int verbose; + +#define CMDLINE_INCLUDE 20 +int cmdline_include_nr = 0; +char *cmdline_include[CMDLINE_INCLUDE]; const char *base_filename; const char *diag_prefix = ""; @@ -39,11 +52,35 @@ const char *gcc_base_dir = GCC_BASE; const char *multiarch_dir = MULTIARCH_TRIPLET; const char *outfile = NULL; -enum flag_type { - FLAG_OFF, - FLAG_ON, - FLAG_FORCE_OFF -}; +enum standard standard = STANDARD_GNU89; + +int arch_big_endian = ARCH_BIG_ENDIAN; +int arch_cmodel = CMODEL_UNKNOWN; +int arch_fp_abi = FP_ABI_NATIVE; +int arch_m64 = ARCH_M64_DEFAULT; +int arch_msize_long = 0; +int arch_os = OS_NATIVE; + +int dbg_compound = 0; +int dbg_dead = 0; +int dbg_domtree = 0; +int dbg_entry = 0; +int dbg_ir = 0; +int dbg_postorder = 0; + +int dump_macro_defs = 0; +int dump_macros_only = 0; + +unsigned long fdump_ir; +int fhosted = 1; +unsigned int fmax_warnings = 100; +int fmem_report = 0; +unsigned long long fmemcpy_max_count = 100000; +unsigned long fpasses = ~0UL; +int fpic = 0; +int fpie = 0; +int fshort_wchar = 0; +int funsigned_char = 0; int Waddress = 0; int Waddress_space = 1; @@ -60,11 +97,11 @@ int Wdeclarationafterstatement = -1; int Wdefault_bitfield_sign = 0; int Wdesignated_init = 1; int Wdo_while = 0; +int Wenum_mismatch = 1; +int Wexternal_function_has_definition = 1; int Wimplicit_int = 1; int Winit_cstring = 0; int Wint_to_pointer_cast = 1; -int Wenum_mismatch = 1; -int Wexternal_function_has_definition = 1; int Wmemcpy_max_count = 1; int Wnewline_eof = 1; int Wnon_pointer_null = 1; @@ -95,43 +132,6 @@ int Wuniversal_initializer = 0; int Wunknown_attribute = 0; int Wvla = 1; -int dump_macro_defs = 0; -int dump_macros_only = 0; - -int dbg_compound = 0; -int dbg_dead = 0; -int dbg_domtree = 0; -int dbg_entry = 0; -int dbg_ir = 0; -int dbg_postorder = 0; - -unsigned long fdump_ir; -int fhosted = 1; -unsigned int fmax_warnings = 100; -int fmem_report = 0; -unsigned long long fmemcpy_max_count = 100000; -unsigned long fpasses = ~0UL; -int fpic = 0; -int fpie = 0; -int fshort_wchar = 0; -int funsigned_char = 0; - -int preprocess_only; - -enum standard standard = STANDARD_GNU89; - -int arch_msize_long = 0; -int arch_m64 = ARCH_M64_DEFAULT; -int arch_big_endian = ARCH_BIG_ENDIAN; -int arch_fp_abi = FP_ABI_NATIVE; -int arch_os = OS_NATIVE; -int arch_cmodel = CMODEL_UNKNOWN; - - -#define CMDLINE_INCLUDE 20 -int cmdline_include_nr = 0; -char *cmdline_include[CMDLINE_INCLUDE]; - //////////////////////////////////////////////////////////////////////////////// // Helpers for option parsing diff --git a/options.h b/options.h index 52d1106e7576..7fd01ec6cebe 100644 --- a/options.h +++ b/options.h @@ -1,26 +1,85 @@ #ifndef OPTIONS_H #define OPTIONS_H -extern int verbose, optimize_level, optimize_size, preprocessing; +enum { + CMODEL_UNKNOWN, + CMODEL_KERNEL, + CMODEL_LARGE, + CMODEL_MEDANY, + CMODEL_MEDIUM, + CMODEL_MEDLOW, + CMODEL_PIC, + CMODEL_SMALL, + CMODEL_TINY, + CMODEL_LAST, +}; + +enum standard { + STANDARD_NONE, + STANDARD_GNU, + STANDARD_C89, + STANDARD_GNU89 = STANDARD_C89 | STANDARD_GNU, + STANDARD_C94, + STANDARD_GNU94 = STANDARD_C94 | STANDARD_GNU, + STANDARD_C99, + STANDARD_GNU99 = STANDARD_C99 | STANDARD_GNU, + STANDARD_C11, + STANDARD_GNU11 = STANDARD_C11 | STANDARD_GNU, + STANDARD_C17, + STANDARD_GNU17 = STANDARD_C17 | STANDARD_GNU, +}; + extern int die_if_error; -extern int repeat_phase; extern int do_output; -extern int gcc_major, gcc_minor, gcc_patchlevel; -extern unsigned int tabstop; +extern int gcc_major; +extern int gcc_minor; +extern int gcc_patchlevel; +extern int optimize_level; +extern int optimize_size; +extern int preprocess_only; +extern int preprocessing; +extern int repeat_phase; +extern int verbose; + +extern int cmdline_include_nr; +extern char *cmdline_include[]; extern const char *base_filename; extern const char *diag_prefix; extern const char *gcc_base_dir; extern const char *multiarch_dir; extern const char *outfile; -extern int cmdline_include_nr; -extern char *cmdline_include[]; -extern char **handle_switch(char *arg, char **next); -extern void handle_switch_finalize(void); +extern enum standard standard; +extern unsigned int tabstop; +extern int arch_big_endian; +extern int arch_cmodel; +extern int arch_fp_abi; +extern int arch_m64; +extern int arch_msize_long; +extern int arch_os; -extern int preprocess_only; +extern int dbg_compound; +extern int dbg_dead; +extern int dbg_domtree; +extern int dbg_entry; +extern int dbg_ir; +extern int dbg_postorder; + +extern int dump_macro_defs; +extern int dump_macros_only; + +extern unsigned long fdump_ir; +extern int fhosted; +extern unsigned int fmax_warnings; +extern int fmem_report; +extern unsigned long long fmemcpy_max_count; +extern unsigned long fpasses; +extern int fpic; +extern int fpie; +extern int fshort_wchar; +extern int funsigned_char; extern int Waddress; extern int Waddress_space; @@ -39,7 +98,6 @@ extern int Wdesignated_init; extern int Wdo_while; extern int Wenum_mismatch; extern int Wexternal_function_has_definition; -extern int Wsparse_error; extern int Wimplicit_int; extern int Winit_cstring; extern int Wint_to_pointer_cast; @@ -62,6 +120,7 @@ extern int Wshadow; extern int Wshift_count_negative; extern int Wshift_count_overflow; extern int Wsizeof_bool; +extern int Wsparse_error; extern int Wstrict_prototypes; extern int Wtautological_compare; extern int Wtransparent_union; @@ -72,61 +131,7 @@ extern int Wuniversal_initializer; extern int Wunknown_attribute; extern int Wvla; -extern int dump_macro_defs; -extern int dump_macros_only; - -extern int dbg_compound; -extern int dbg_dead; -extern int dbg_domtree; -extern int dbg_entry; -extern int dbg_ir; -extern int dbg_postorder; - -extern unsigned int fmax_warnings; -extern int fmem_report; -extern unsigned long fdump_ir; -extern int fhosted; -extern unsigned long long fmemcpy_max_count; -extern unsigned long fpasses; -extern int fpic; -extern int fpie; -extern int fshort_wchar; -extern int funsigned_char; - -extern int arch_msize_long; -extern int arch_m64; -extern int arch_big_endian; -extern int arch_fp_abi; -extern int arch_os; - -enum { - CMODEL_UNKNOWN, - CMODEL_KERNEL, - CMODEL_LARGE, - CMODEL_MEDANY, - CMODEL_MEDIUM, - CMODEL_MEDLOW, - CMODEL_PIC, - CMODEL_SMALL, - CMODEL_TINY, - CMODEL_LAST, -}; -extern int arch_cmodel; - -enum standard { - STANDARD_NONE, - STANDARD_GNU, - STANDARD_C89, - STANDARD_GNU89 = STANDARD_C89 | STANDARD_GNU, - STANDARD_C94, - STANDARD_GNU94 = STANDARD_C94 | STANDARD_GNU, - STANDARD_C99, - STANDARD_GNU99 = STANDARD_C99 | STANDARD_GNU, - STANDARD_C11, - STANDARD_GNU11 = STANDARD_C11 | STANDARD_GNU, - STANDARD_C17, - STANDARD_GNU17 = STANDARD_C17 | STANDARD_GNU, -}; -extern enum standard standard; +extern char **handle_switch(char *arg, char **next); +extern void handle_switch_finalize(void); #endif From patchwork Sun Jul 5 13:02:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11644397 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DCF5913B4 for ; Sun, 5 Jul 2020 13:02:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BADBD2075D for ; Sun, 5 Jul 2020 13:02:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NFJc6EiM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727052AbgGENCn (ORCPT ); Sun, 5 Jul 2020 09:02:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727031AbgGENCn (ORCPT ); Sun, 5 Jul 2020 09:02:43 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58EE3C061794 for ; Sun, 5 Jul 2020 06:02:42 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id d16so25545098edz.12 for ; Sun, 05 Jul 2020 06:02:42 -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 :mime-version:content-transfer-encoding; bh=XftDDHJLGP4abIDDD34XPeZJNkIQZFz4M9hvz8t7ynw=; b=NFJc6EiM+qWO0V2jxSmsf7g38CYH9/xH3b6Zn1hUCxL8S06RRYVc3EfhTMZ9TMfZP/ +JWwwNjerbXnaMdudWIDQ/JldWuO6iEEHm/WavvB26Nhotk7ZGvHpJ7ZS4HEsu6bXOjm tIqI+lnNZjv9ZGbGBWZRfbxvyAuuiHsqoUcLFgRS3YWF10EAHdKglieFTHZb1+yzDsY/ Tq5vbUHUo/aZG9HViKfnw7zfJCgsEmU9VAl1bfffhFdAKht0hB4kzejhZQQFo9ek3zFO XaDv49UfgJIj6Tdij/5kBS4XCI95xxgkpYvBqbA1jQe1STqzA4uyH/UxZQC5vPlQCjm9 vwcw== 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:mime-version:content-transfer-encoding; bh=XftDDHJLGP4abIDDD34XPeZJNkIQZFz4M9hvz8t7ynw=; b=CYnCcjEZ2J4iWPWxeRCZ/m5tLkqm2ydIGiiwZtYRiQzgDp5AlvWlrjMglVRrgdlYAL M3ZDgXMv+3ruIh0+HyP4iL4TT/adaB8iGfYAUKjz5fpOvIoxr5Tjf93Am8LYqP45BNbl 4BICVCqpq4yn5bcPWy6lyyrzTwcVb4e8/hk0gfy9wg7djDVFn5DLCSgq8v+CP9dtpLUe /1ggQ8rCuiCAdTF82rM0zZ08r44pLtmtDMvfgRFpgt8+xMcNZRoLC0vM8LWdeYyiQzwJ pBeKSm0y3pQLvWoBCzFIwQf19Ov/Ngvd1CGfOti9SmHeommTIwq1s4OPOPTtXs47HR+V uLlg== X-Gm-Message-State: AOAM533uR1mhkc2KhiSaL6H19bRUAx8tFeFCcBAjzVQcGXfClUzsLlPR msPc4gCfGzWkZ5gjCKmG+4RuXL97 X-Google-Smtp-Source: ABdhPJw5/XNMRPtmStMiBhQZ/MM0+Ook2GmSyhFMidTntyXWqHoT27XXkUi9NKvlGo4qMZOpvS0ZCQ== X-Received: by 2002:a50:aca6:: with SMTP id x35mr48675753edc.328.1593954160696; Sun, 05 Jul 2020 06:02:40 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7f9:7600:a542:d3fb:b75a:dec5]) by smtp.gmail.com with ESMTPSA id x16sm19535945edr.52.2020.07.05.06.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jul 2020 06:02:40 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 13/15] cleanup: move predefines in a separate file Date: Sun, 5 Jul 2020 15:02:18 +0200 Message-Id: <20200705130220.26230-14-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> References: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Now that option parsing have moved to a separate file, move everything related to predefined macros to a separate file too. Signed-off-by: Luc Van Oostenryck --- Makefile | 1 + lib.c | 221 --------------------------------------------------- lib.h | 1 + predefine.c | 225 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 227 insertions(+), 221 deletions(-) create mode 100644 predefine.c diff --git a/Makefile b/Makefile index dce666d27c41..f4483f5a1deb 100644 --- a/Makefile +++ b/Makefile @@ -54,6 +54,7 @@ LIB_OBJS += opcode.o LIB_OBJS += optimize.o LIB_OBJS += options.o LIB_OBJS += parse.o +LIB_OBJS += predefine.o LIB_OBJS += pre-process.o LIB_OBJS += ptrlist.o LIB_OBJS += ptrmap.o diff --git a/lib.c b/lib.c index 53b107d2d063..fd1fe6cb3ba5 100644 --- a/lib.c +++ b/lib.c @@ -248,227 +248,6 @@ void add_pre_buffer(const char *fmt, ...) pre_buffer_end = end; } -//////////////////////////////////////////////////////////////////////////////// -// Predefines - -#define PTYPE_SIZEOF (1U << 0) -#define PTYPE_T (1U << 1) -#define PTYPE_MAX (1U << 2) -#define PTYPE_MIN (1U << 3) -#define PTYPE_WIDTH (1U << 4) -#define PTYPE_TYPE (1U << 5) -#define PTYPE_ALL (PTYPE_MAX|PTYPE_SIZEOF|PTYPE_WIDTH) -#define PTYPE_ALL_T (PTYPE_MAX|PTYPE_SIZEOF|PTYPE_WIDTH|PTYPE_T) - -static void predefined_sizeof(const char *name, const char *suffix, unsigned bits) -{ - char buf[32]; - - snprintf(buf, sizeof(buf), "__SIZEOF_%s%s__", name, suffix); - predefine(buf, 1, "%d", bits/8); -} - -static void predefined_width(const char *name, unsigned bits) -{ - char buf[32]; - - snprintf(buf, sizeof(buf), "__%s_WIDTH__", name); - predefine(buf, 1, "%d", bits); -} - -static void predefined_max(const char *name, struct symbol *type) -{ - const char *suffix = builtin_type_suffix(type); - unsigned bits = type->bit_size - is_signed_type(type); - unsigned long long max = bits_mask(bits); - char buf[32]; - - snprintf(buf, sizeof(buf), "__%s_MAX__", name); - predefine(buf, 1, "%#llx%s", max, suffix); -} - -static void predefined_min(const char *name, struct symbol *type) -{ - const char *suffix = builtin_type_suffix(type); - char buf[32]; - - snprintf(buf, sizeof(buf), "__%s_MIN__", name); - - if (is_signed_type(type)) - predefine(buf, 1, "(-__%s_MAX__ - 1)", name); - else - predefine(buf, 1, "0%s", suffix); -} - -static void predefined_type(const char *name, struct symbol *type) -{ - const char *typename = builtin_typename(type); - add_pre_buffer("#weak_define __%s_TYPE__ %s\n", name, typename); -} - -static void predefined_ctype(const char *name, struct symbol *type, int flags) -{ - unsigned bits = type->bit_size; - - if (flags & PTYPE_SIZEOF) { - const char *suffix = (flags & PTYPE_T) ? "_T" : ""; - predefined_sizeof(name, suffix, bits); - } - if (flags & PTYPE_MAX) - predefined_max(name, type); - if (flags & PTYPE_MIN) - predefined_min(name, type); - if (flags & PTYPE_TYPE) - predefined_type(name, type); - if (flags & PTYPE_WIDTH) - predefined_width(name, bits); -} - -static void predefined_macros(void) -{ - predefine("__CHECKER__", 0, "1"); - predefine("__GNUC__", 1, "%d", gcc_major); - predefine("__GNUC_MINOR__", 1, "%d", gcc_minor); - predefine("__GNUC_PATCHLEVEL__", 1, "%d", gcc_patchlevel); - - predefine("__STDC__", 1, "1"); - predefine("__STDC_HOSTED__", 0, fhosted ? "1" : "0"); - switch (standard) { - default: - break; - - case STANDARD_C94: - predefine("__STDC_VERSION__", 1, "199409L"); - break; - - case STANDARD_C99: - case STANDARD_GNU99: - predefine("__STDC_VERSION__", 1, "199901L"); - break; - - case STANDARD_C11: - case STANDARD_GNU11: - predefine("__STDC_VERSION__", 1, "201112L"); - break; - case STANDARD_C17: - case STANDARD_GNU17: - predefine("__STDC_VERSION__", 1, "201710L"); - break; - } - if (!(standard & STANDARD_GNU) && (standard != STANDARD_NONE)) - predefine("__STRICT_ANSI__", 1, "1"); - if (standard >= STANDARD_C11) { - predefine("__STDC_NO_ATOMICS__", 1, "1"); - predefine("__STDC_NO_COMPLEX__", 1, "1"); - predefine("__STDC_NO_THREADS__", 1, "1"); - } - - predefine("__CHAR_BIT__", 1, "%d", bits_in_char); - if (funsigned_char) - predefine("__CHAR_UNSIGNED__", 1, "1"); - - predefined_ctype("SHORT", &short_ctype, PTYPE_SIZEOF); - predefined_ctype("SHRT", &short_ctype, PTYPE_MAX|PTYPE_WIDTH); - predefined_ctype("SCHAR", &schar_ctype, PTYPE_MAX|PTYPE_WIDTH); - predefined_ctype("WCHAR", wchar_ctype, PTYPE_ALL_T|PTYPE_MIN|PTYPE_TYPE); - predefined_ctype("WINT", wint_ctype, PTYPE_ALL_T|PTYPE_MIN|PTYPE_TYPE); - predefined_ctype("CHAR16", &ushort_ctype, PTYPE_TYPE); - predefined_ctype("CHAR32", uint32_ctype, PTYPE_TYPE); - - predefined_ctype("INT", &int_ctype, PTYPE_ALL); - predefined_ctype("LONG", &long_ctype, PTYPE_ALL); - predefined_ctype("LONG_LONG", &llong_ctype, PTYPE_ALL); - - predefined_ctype("INT8", &schar_ctype, PTYPE_MAX|PTYPE_TYPE); - predefined_ctype("UINT8", &uchar_ctype, PTYPE_MAX|PTYPE_TYPE); - predefined_ctype("INT16", &short_ctype, PTYPE_MAX|PTYPE_TYPE); - predefined_ctype("UINT16", &ushort_ctype, PTYPE_MAX|PTYPE_TYPE); - predefined_ctype("INT32", int32_ctype, PTYPE_MAX|PTYPE_TYPE); - predefined_ctype("UINT32", uint32_ctype, PTYPE_MAX|PTYPE_TYPE); - predefined_ctype("INT64", int64_ctype, PTYPE_MAX|PTYPE_TYPE); - predefined_ctype("UINT64", uint64_ctype, PTYPE_MAX|PTYPE_TYPE); - - predefined_ctype("INTMAX", intmax_ctype, PTYPE_MAX|PTYPE_TYPE|PTYPE_WIDTH); - predefined_ctype("UINTMAX", uintmax_ctype, PTYPE_MAX|PTYPE_TYPE); - predefined_ctype("INTPTR", ssize_t_ctype, PTYPE_MAX|PTYPE_TYPE|PTYPE_WIDTH); - predefined_ctype("UINTPTR", size_t_ctype, PTYPE_MAX|PTYPE_TYPE); - predefined_ctype("PTRDIFF", ssize_t_ctype, PTYPE_ALL_T|PTYPE_TYPE); - predefined_ctype("SIZE", size_t_ctype, PTYPE_ALL_T|PTYPE_TYPE); - predefined_ctype("POINTER", &ptr_ctype, PTYPE_SIZEOF); - - predefined_sizeof("FLOAT", "", bits_in_float); - predefined_sizeof("DOUBLE", "", bits_in_double); - predefined_sizeof("LONG_DOUBLE", "", bits_in_longdouble); - - if (arch_target->has_int128) - predefined_sizeof("INT128", "", 128); - - predefine("__ORDER_LITTLE_ENDIAN__", 1, "1234"); - predefine("__ORDER_BIG_ENDIAN__", 1, "4321"); - predefine("__ORDER_PDP_ENDIAN__", 1, "3412"); - if (arch_big_endian) { - predefine("__BIG_ENDIAN__", 1, "1"); - predefine("__BYTE_ORDER__", 1, "__ORDER_BIG_ENDIAN__"); - } else { - predefine("__LITTLE_ENDIAN__", 1, "1"); - predefine("__BYTE_ORDER__", 1, "__ORDER_LITTLE_ENDIAN__"); - } - - if (optimize_level) - predefine("__OPTIMIZE__", 0, "1"); - if (optimize_size) - predefine("__OPTIMIZE_SIZE__", 0, "1"); - - predefine("__PRAGMA_REDEFINE_EXTNAME", 1, "1"); - - // Temporary hacks - predefine("__extension__", 0, NULL); - predefine("__pragma__", 0, NULL); - - switch (arch_m64) { - case ARCH_LP32: - break; - case ARCH_X32: - predefine("__ILP32__", 1, "1"); - predefine("_ILP32", 1, "1"); - break; - case ARCH_LP64: - predefine("__LP64__", 1, "1"); - predefine("_LP64", 1, "1"); - break; - case ARCH_LLP64: - predefine("__LLP64__", 1, "1"); - break; - } - - if (fpic) { - predefine("__pic__", 0, "%d", fpic); - predefine("__PIC__", 0, "%d", fpic); - } - if (fpie) { - predefine("__pie__", 0, "%d", fpie); - predefine("__PIE__", 0, "%d", fpie); - } - - if (arch_target->predefine) - arch_target->predefine(arch_target); - - if (arch_os >= OS_UNIX) { - predefine("__unix__", 1, "1"); - predefine("__unix", 1, "1"); - predefine_nostd("unix"); - } - - if (arch_os == OS_SUNOS) { - predefine("__sun__", 1, "1"); - predefine("__sun", 1, "1"); - predefine_nostd("sun"); - predefine("__svr4__", 1, "1"); - } -} - -//////////////////////////////////////////////////////////////////////////////// - static void create_builtin_stream(void) { // Temporary hack diff --git a/lib.h b/lib.h index b47505f638b4..81253a3e7ee5 100644 --- a/lib.h +++ b/lib.h @@ -130,6 +130,7 @@ enum phase { extern void add_pre_buffer(const char *fmt, ...) FORMAT_ATTR(1); extern void predefine(const char *name, int weak, const char *fmt, ...) FORMAT_ATTR(3); extern void predefine_nostd(const char *name); +extern void predefined_macros(void); extern void dump_macro_definitions(void); diff --git a/predefine.c b/predefine.c new file mode 100644 index 000000000000..ff457b389480 --- /dev/null +++ b/predefine.c @@ -0,0 +1,225 @@ +// SPDX-License-Identifier: MIT +// Copyright (C) 2017-2020 Luc Van Oostenryck. + +#include + +#include "lib.h" +#include "machine.h" +#include "symbol.h" + +#define PTYPE_SIZEOF (1U << 0) +#define PTYPE_T (1U << 1) +#define PTYPE_MAX (1U << 2) +#define PTYPE_MIN (1U << 3) +#define PTYPE_WIDTH (1U << 4) +#define PTYPE_TYPE (1U << 5) +#define PTYPE_ALL (PTYPE_MAX|PTYPE_SIZEOF|PTYPE_WIDTH) +#define PTYPE_ALL_T (PTYPE_MAX|PTYPE_SIZEOF|PTYPE_WIDTH|PTYPE_T) + + +static void predefined_sizeof(const char *name, const char *suffix, unsigned bits) +{ + char buf[32]; + + snprintf(buf, sizeof(buf), "__SIZEOF_%s%s__", name, suffix); + predefine(buf, 1, "%d", bits/8); +} + +static void predefined_width(const char *name, unsigned bits) +{ + char buf[32]; + + snprintf(buf, sizeof(buf), "__%s_WIDTH__", name); + predefine(buf, 1, "%d", bits); +} + +static void predefined_max(const char *name, struct symbol *type) +{ + const char *suffix = builtin_type_suffix(type); + unsigned bits = type->bit_size - is_signed_type(type); + unsigned long long max = bits_mask(bits); + char buf[32]; + + snprintf(buf, sizeof(buf), "__%s_MAX__", name); + predefine(buf, 1, "%#llx%s", max, suffix); +} + +static void predefined_min(const char *name, struct symbol *type) +{ + const char *suffix = builtin_type_suffix(type); + char buf[32]; + + snprintf(buf, sizeof(buf), "__%s_MIN__", name); + + if (is_signed_type(type)) + predefine(buf, 1, "(-__%s_MAX__ - 1)", name); + else + predefine(buf, 1, "0%s", suffix); +} + +static void predefined_type(const char *name, struct symbol *type) +{ + const char *typename = builtin_typename(type); + add_pre_buffer("#weak_define __%s_TYPE__ %s\n", name, typename); +} + +static void predefined_ctype(const char *name, struct symbol *type, int flags) +{ + unsigned bits = type->bit_size; + + if (flags & PTYPE_SIZEOF) { + const char *suffix = (flags & PTYPE_T) ? "_T" : ""; + predefined_sizeof(name, suffix, bits); + } + if (flags & PTYPE_MAX) + predefined_max(name, type); + if (flags & PTYPE_MIN) + predefined_min(name, type); + if (flags & PTYPE_TYPE) + predefined_type(name, type); + if (flags & PTYPE_WIDTH) + predefined_width(name, bits); +} + +void predefined_macros(void) +{ + predefine("__CHECKER__", 0, "1"); + predefine("__GNUC__", 1, "%d", gcc_major); + predefine("__GNUC_MINOR__", 1, "%d", gcc_minor); + predefine("__GNUC_PATCHLEVEL__", 1, "%d", gcc_patchlevel); + + predefine("__STDC__", 1, "1"); + predefine("__STDC_HOSTED__", 0, fhosted ? "1" : "0"); + switch (standard) { + default: + break; + + case STANDARD_C94: + predefine("__STDC_VERSION__", 1, "199409L"); + break; + + case STANDARD_C99: + case STANDARD_GNU99: + predefine("__STDC_VERSION__", 1, "199901L"); + break; + + case STANDARD_C11: + case STANDARD_GNU11: + predefine("__STDC_VERSION__", 1, "201112L"); + break; + case STANDARD_C17: + case STANDARD_GNU17: + predefine("__STDC_VERSION__", 1, "201710L"); + break; + } + if (!(standard & STANDARD_GNU) && (standard != STANDARD_NONE)) + predefine("__STRICT_ANSI__", 1, "1"); + if (standard >= STANDARD_C11) { + predefine("__STDC_NO_ATOMICS__", 1, "1"); + predefine("__STDC_NO_COMPLEX__", 1, "1"); + predefine("__STDC_NO_THREADS__", 1, "1"); + } + + predefine("__CHAR_BIT__", 1, "%d", bits_in_char); + if (funsigned_char) + predefine("__CHAR_UNSIGNED__", 1, "1"); + + predefined_ctype("SHORT", &short_ctype, PTYPE_SIZEOF); + predefined_ctype("SHRT", &short_ctype, PTYPE_MAX|PTYPE_WIDTH); + predefined_ctype("SCHAR", &schar_ctype, PTYPE_MAX|PTYPE_WIDTH); + predefined_ctype("WCHAR", wchar_ctype, PTYPE_ALL_T|PTYPE_MIN|PTYPE_TYPE); + predefined_ctype("WINT", wint_ctype, PTYPE_ALL_T|PTYPE_MIN|PTYPE_TYPE); + predefined_ctype("CHAR16", &ushort_ctype, PTYPE_TYPE); + predefined_ctype("CHAR32", uint32_ctype, PTYPE_TYPE); + + predefined_ctype("INT", &int_ctype, PTYPE_ALL); + predefined_ctype("LONG", &long_ctype, PTYPE_ALL); + predefined_ctype("LONG_LONG", &llong_ctype, PTYPE_ALL); + + predefined_ctype("INT8", &schar_ctype, PTYPE_MAX|PTYPE_TYPE); + predefined_ctype("UINT8", &uchar_ctype, PTYPE_MAX|PTYPE_TYPE); + predefined_ctype("INT16", &short_ctype, PTYPE_MAX|PTYPE_TYPE); + predefined_ctype("UINT16", &ushort_ctype, PTYPE_MAX|PTYPE_TYPE); + predefined_ctype("INT32", int32_ctype, PTYPE_MAX|PTYPE_TYPE); + predefined_ctype("UINT32", uint32_ctype, PTYPE_MAX|PTYPE_TYPE); + predefined_ctype("INT64", int64_ctype, PTYPE_MAX|PTYPE_TYPE); + predefined_ctype("UINT64", uint64_ctype, PTYPE_MAX|PTYPE_TYPE); + + predefined_ctype("INTMAX", intmax_ctype, PTYPE_MAX|PTYPE_TYPE|PTYPE_WIDTH); + predefined_ctype("UINTMAX", uintmax_ctype, PTYPE_MAX|PTYPE_TYPE); + predefined_ctype("INTPTR", ssize_t_ctype, PTYPE_MAX|PTYPE_TYPE|PTYPE_WIDTH); + predefined_ctype("UINTPTR", size_t_ctype, PTYPE_MAX|PTYPE_TYPE); + predefined_ctype("PTRDIFF", ssize_t_ctype, PTYPE_ALL_T|PTYPE_TYPE); + predefined_ctype("SIZE", size_t_ctype, PTYPE_ALL_T|PTYPE_TYPE); + predefined_ctype("POINTER", &ptr_ctype, PTYPE_SIZEOF); + + predefined_sizeof("FLOAT", "", bits_in_float); + predefined_sizeof("DOUBLE", "", bits_in_double); + predefined_sizeof("LONG_DOUBLE", "", bits_in_longdouble); + + if (arch_target->has_int128) + predefined_sizeof("INT128", "", 128); + + predefine("__ORDER_LITTLE_ENDIAN__", 1, "1234"); + predefine("__ORDER_BIG_ENDIAN__", 1, "4321"); + predefine("__ORDER_PDP_ENDIAN__", 1, "3412"); + if (arch_big_endian) { + predefine("__BIG_ENDIAN__", 1, "1"); + predefine("__BYTE_ORDER__", 1, "__ORDER_BIG_ENDIAN__"); + } else { + predefine("__LITTLE_ENDIAN__", 1, "1"); + predefine("__BYTE_ORDER__", 1, "__ORDER_LITTLE_ENDIAN__"); + } + + if (optimize_level) + predefine("__OPTIMIZE__", 0, "1"); + if (optimize_size) + predefine("__OPTIMIZE_SIZE__", 0, "1"); + + predefine("__PRAGMA_REDEFINE_EXTNAME", 1, "1"); + + // Temporary hacks + predefine("__extension__", 0, NULL); + predefine("__pragma__", 0, NULL); + + switch (arch_m64) { + case ARCH_LP32: + break; + case ARCH_X32: + predefine("__ILP32__", 1, "1"); + predefine("_ILP32", 1, "1"); + break; + case ARCH_LP64: + predefine("__LP64__", 1, "1"); + predefine("_LP64", 1, "1"); + break; + case ARCH_LLP64: + predefine("__LLP64__", 1, "1"); + break; + } + + if (fpic) { + predefine("__pic__", 0, "%d", fpic); + predefine("__PIC__", 0, "%d", fpic); + } + if (fpie) { + predefine("__pie__", 0, "%d", fpie); + predefine("__PIE__", 0, "%d", fpie); + } + + if (arch_target->predefine) + arch_target->predefine(arch_target); + + if (arch_os >= OS_UNIX) { + predefine("__unix__", 1, "1"); + predefine("__unix", 1, "1"); + predefine_nostd("unix"); + } + + if (arch_os == OS_SUNOS) { + predefine("__sun__", 1, "1"); + predefine("__sun", 1, "1"); + predefine_nostd("sun"); + predefine("__svr4__", 1, "1"); + } +} From patchwork Sun Jul 5 13:02:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11644399 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3C14814DD for ; Sun, 5 Jul 2020 13:02:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2456920747 for ; Sun, 5 Jul 2020 13:02:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YmxxW8Pn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727031AbgGENCn (ORCPT ); Sun, 5 Jul 2020 09:02:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727053AbgGENCn (ORCPT ); Sun, 5 Jul 2020 09:02:43 -0400 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 305BCC08C5DE for ; Sun, 5 Jul 2020 06:02:43 -0700 (PDT) Received: by mail-ej1-x644.google.com with SMTP id p20so39548121ejd.13 for ; Sun, 05 Jul 2020 06:02:43 -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 :mime-version:content-transfer-encoding; bh=hfkNsG4Ak/hs2nUpGg9DlhfS8mppNAS7YLoSweae/2U=; b=YmxxW8PnwG5FX5RO1kHjNyFK/U05BmJrcuRrMZmkEnYy5fYBjjLelbSLfaa+2AJnQy vbgX5KVL8NGEfGkAJ+0LRBy5iPDsUFaDYMUo2ZVPGUF41dr2uUqsgRdncZmos6s1Bp7g vyy6ZIkJvXIHmJ/I8y+VuP8ur6seqfSSvq0AR7btE21Pua3f3biAImh9IMlarEJvelF1 JBGrGwXCWAaqcWEDvaFPeITLhbw7F3uq0A/togtJp2rcaghZ+GIZ8GKHZqYxLa/kWP8e Y1T0/0aKrhp1638w5illpLgSdtdXLTWbxwG1cwOJs9oDPA7Tf8UlqdUGhuFo+VpsuO50 7ekw== 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:mime-version:content-transfer-encoding; bh=hfkNsG4Ak/hs2nUpGg9DlhfS8mppNAS7YLoSweae/2U=; b=scrNWy6BDpbaZRfprzuMM79BmJ/v9MZoBxdych3fM+bFNF6Y7Z60bsQzIchCEo/+J4 HnadbwR9HCbooQpmpLJ6v8OHpRL3erhSQXjwGkyBaLUEMPTu3BOmZudDT+v1PREsZsBm AqVL1RaRbbP1cOVkE2hnopQWGYqaZIuy8whNB/KA6s10S/wQ8yWl+uRpqJz3sfWBf8Eq uPRJWcA1+eIgUUvmrpPaSnjje4upeWb+1rTCWoofVSMXhbkGA713ijUeKsPlqFICwuMj LYdeP7DmlmJrQNUMyPkIUQX4jrOnBSOvrTCPA3lBlF/GxnhVBgVL5JDgGTuDSi2X9YCp 4Bkg== X-Gm-Message-State: AOAM533gm8zeaMhZIvxuRr8XIHkoQXK/pldEnXfmZ+Ub0aAiTuc6y/Y1 HwKCGLQP7/+6EXzh24jnuLXHaU/o X-Google-Smtp-Source: ABdhPJxhtJtsbyiEyKYjQzCQauE+0dgcEz99oaacPckh1b+gEqTz/Ipa5Dt2jUrjzKEvHN+c+Fe99Q== X-Received: by 2002:a17:906:4d4c:: with SMTP id b12mr38741348ejv.506.1593954161618; Sun, 05 Jul 2020 06:02:41 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7f9:7600:a542:d3fb:b75a:dec5]) by smtp.gmail.com with ESMTPSA id x16sm19535945edr.52.2020.07.05.06.02.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jul 2020 06:02:41 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 14/15] cleanup: move parsing helpers to parse.c Date: Sun, 5 Jul 2020 15:02:19 +0200 Message-Id: <20200705130220.26230-15-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> References: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org lib.c contains 2-3 helpers for parsing. Move them to parse.c. Signed-off-by: Luc Van Oostenryck --- lib.c | 38 -------------------------------------- parse.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/lib.c b/lib.c index fd1fe6cb3ba5..f512be2e1a43 100644 --- a/lib.c +++ b/lib.c @@ -50,44 +50,6 @@ #include "bits.h" -struct token *skip_to(struct token *token, int op) -{ - while (!match_op(token, op) && !eof_token(token)) - token = token->next; - return token; -} - -static struct token bad_token = { .pos.type = TOKEN_BAD }; -struct token *expect(struct token *token, int op, const char *where) -{ - if (!match_op(token, op)) { - if (token != &bad_token) { - bad_token.next = token; - sparse_error(token->pos, "Expected %s %s", show_special(op), where); - sparse_error(token->pos, "got %s", show_token(token)); - } - if (op == ';') - return skip_to(token, op); - return &bad_token; - } - return token->next; -} - -/// -// issue an error message on new parsing errors -// @token: the current token -// @errmsg: the error message -// If the current token is from a previous error, an error message -// has already been issued, so nothing more is done. -// Otherwise, @errmsg is displayed followed by the current token. -void unexpected(struct token *token, const char *errmsg) -{ - if (token == &bad_token) - return; - sparse_error(token->pos, "%s", errmsg); - sparse_error(token->pos, "got %s", show_token(token)); -} - unsigned int hexval(unsigned int c) { int retval = 256; diff --git a/parse.c b/parse.c index 70d8b237ce5e..cea208395090 100644 --- a/parse.c +++ b/parse.c @@ -655,6 +655,44 @@ void init_parser(int stream) } +struct token *skip_to(struct token *token, int op) +{ + while (!match_op(token, op) && !eof_token(token)) + token = token->next; + return token; +} + +static struct token bad_token = { .pos.type = TOKEN_BAD }; +struct token *expect(struct token *token, int op, const char *where) +{ + if (!match_op(token, op)) { + if (token != &bad_token) { + bad_token.next = token; + sparse_error(token->pos, "Expected %s %s", show_special(op), where); + sparse_error(token->pos, "got %s", show_token(token)); + } + if (op == ';') + return skip_to(token, op); + return &bad_token; + } + return token->next; +} + +/// +// issue an error message on new parsing errors +// @token: the current token +// @errmsg: the error message +// If the current token is from a previous error, an error message +// has already been issued, so nothing more is done. +// Otherwise, @errmsg is displayed followed by the current token. +void unexpected(struct token *token, const char *errmsg) +{ + if (token == &bad_token) + return; + sparse_error(token->pos, "%s", errmsg); + sparse_error(token->pos, "got %s", show_token(token)); +} + // Add a symbol to the list of function-local symbols static void fn_local_symbol(struct symbol *sym) { From patchwork Sun Jul 5 13:02:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11644401 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 00F6392A for ; Sun, 5 Jul 2020 13:02:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DF6ED2075D for ; Sun, 5 Jul 2020 13:02:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="s8SH+BOd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727057AbgGENCo (ORCPT ); Sun, 5 Jul 2020 09:02:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727053AbgGENCo (ORCPT ); Sun, 5 Jul 2020 09:02:44 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12E77C061794 for ; Sun, 5 Jul 2020 06:02:44 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id dp18so39584686ejc.8 for ; Sun, 05 Jul 2020 06:02:44 -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 :mime-version:content-transfer-encoding; bh=dgtvhZLfdp9O3gftKqMBNkndvT7e8+IujNOk46Vo20Q=; b=s8SH+BOdas6H+4zvjIcvB7RBDRScWq69MTq7953t6ZLFtRepY7oy7gSqgPTxcD1354 YT/54NNWY1vmGuS0Oc/AjqUPzWaVLme+U7tlI0XTzD47OKDDbx2ECBE8eNRJpNzPcdH6 CYkAosoB+N2U5e2V2sKqVvi6ZksaDiyx+LK6/JiOL1hlIZMb/GuKn2idhDJMNjB6pUqX 2z0/KauJ/vFeywfXPyaxRBC7c3Rd9T0KQbpfKTsJSi77GcKKCL+BbAX2X6XUE7R5W9Y8 b0HVUFpCSjtG/d+P50GpbfPJcAI8F2y4gW3XCmSuCt8MIygQVxEFUjYufesqVdSf74gl sk4Q== 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:mime-version:content-transfer-encoding; bh=dgtvhZLfdp9O3gftKqMBNkndvT7e8+IujNOk46Vo20Q=; b=i1RPzxwVwtQVOcczo3dFJdPnfmjYPErG9I1h3HDKEUrrSiFAhdkZqzxuNeJHhDwyKS a7SDhNjZGf/D+bKECa7e92ThRfHt2Zm8JYodf0xIBsEHtH7OQ2YfubeF0VdIBt0/luIU ssUaQipFolIgqxrtiD0yIlKMxSyJ3fx/2JutbJCFQ5qsNnC2pyuLfk5N7nVY4yHSkeDz 39OvfzffHgoOszPPpKjWH/q38xg71Q7ru52RROrvBERzoB8ih+jegdy3n/uBqhwtxGwZ E8Z46clXPdqsAUrkiW2knETJFwjAMp17FbrZmWtRpbDeRoCmcUwVGyYvYDpVRKDsSWSn stEw== X-Gm-Message-State: AOAM5315zdlj3bEC7HDZ80m3tcGwLfSD4ASS3tOzS/ONjMEXVKlPl9xw l/GJ/XeBUJCWuxJEhEgaUy2cMvpJ X-Google-Smtp-Source: ABdhPJypwY8IYgrloAf/kuNKi4R9tjLflZLcdx30WRcdI8Fbp7ShLQ1rENx37+f8TJvKZo17iyIZPw== X-Received: by 2002:a17:906:2a5b:: with SMTP id k27mr38424331eje.82.1593954162574; Sun, 05 Jul 2020 06:02:42 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7f9:7600:a542:d3fb:b75a:dec5]) by smtp.gmail.com with ESMTPSA id x16sm19535945edr.52.2020.07.05.06.02.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jul 2020 06:02:42 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 15/15] cleanup: move hexval() to utils.c Date: Sun, 5 Jul 2020 15:02:20 +0200 Message-Id: <20200705130220.26230-16-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> References: <20200705130220.26230-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Now lib.c contains almost nothing else than library entrypoints. Move a small utility, hexval(), to utils.c to complete this cleanup. Signed-off-by: Luc Van Oostenryck --- lib.c | 17 ----------------- lib.h | 2 -- utils.c | 17 +++++++++++++++++ utils.h | 4 ++++ 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/lib.c b/lib.c index f512be2e1a43..57c89a16448e 100644 --- a/lib.c +++ b/lib.c @@ -50,23 +50,6 @@ #include "bits.h" -unsigned int hexval(unsigned int c) -{ - int retval = 256; - switch (c) { - case '0'...'9': - retval = c - '0'; - break; - case 'a'...'f': - retval = c - 'a' + 10; - break; - case 'A'...'F': - retval = c - 'A' + 10; - break; - } - return retval; -} - static void do_warn(const char *type, struct position pos, const char * fmt, va_list args) { static char buffer[512]; diff --git a/lib.h b/lib.h index 81253a3e7ee5..46483f2bed5c 100644 --- a/lib.h +++ b/lib.h @@ -45,8 +45,6 @@ #endif -extern unsigned int hexval(unsigned int c); - struct position { unsigned int type:6, stream:14, diff --git a/utils.c b/utils.c index 094df3f9bf1c..72fff00ff91b 100644 --- a/utils.c +++ b/utils.c @@ -8,6 +8,23 @@ #include +unsigned int hexval(unsigned int c) +{ + int retval = 256; + switch (c) { + case '0'...'9': + retval = c - '0'; + break; + case 'a'...'f': + retval = c - 'a' + 10; + break; + case 'A'...'F': + retval = c - 'A' + 10; + break; + } + return retval; +} + void *xmemdup(const void *src, size_t len) { return memcpy(__alloc_bytes(len), src, len); diff --git a/utils.h b/utils.h index 7bd14f467799..079fb02a3e94 100644 --- a/utils.h +++ b/utils.h @@ -8,6 +8,10 @@ #include #include +/// +// return the value coresponding to an hexadecimal digit +unsigned int hexval(unsigned int c); + /// // duplicate a memory buffer in a newly allocated buffer. // @src: a pointer to the memory buffer to be duplicated