From patchwork Thu Sep 28 17:43:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Moon X-Patchwork-Id: 76856 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BEE363858020 for ; Thu, 28 Sep 2023 17:44:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BEE363858020 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695923075; bh=sIL3t21fC+rZ6V5C2lAbNrAlxzkd0YLkNbTh3x20KWw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Help: List-Subscribe:From:Reply-To:Cc:From; b=QAVuESPqeoASrUJBKg0i8blA0x36OqgVVgX36YaGJyS8uDrc5aMtTy3z6R3T274Ri v/U+x2EbqloxRCyM2ohOiAZpjFBMTLOJw4ZjrwJJ27qm7bSdcVIWQbc7ULo5FQKfrc rJWerjRuOQ8hx6fvQdqzU1V5w1N90d9zljIJXeoQ= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by sourceware.org (Postfix) with ESMTPS id AFD313858C52 for ; Thu, 28 Sep 2023 17:44:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AFD313858C52 Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38SFghYM017236; Thu, 28 Sep 2023 17:44:26 GMT Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3td8wdrvcw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 28 Sep 2023 17:44:25 +0000 Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 38SHi6KU007229 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 28 Sep 2023 17:44:06 GMT Received: from hu-johmoo-lv.qualcomm.com (10.49.16.6) by nalasex01c.na.qualcomm.com (10.47.97.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Thu, 28 Sep 2023 10:44:06 -0700 To: , Dodji Seketeli Subject: [PATCH] suppression: Add "changed_enumerators_regexp" property Date: Thu, 28 Sep 2023 10:43:44 -0700 Message-ID: <20230928174344.8268-1-quic_johmoo@quicinc.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) To nalasex01c.na.qualcomm.com (10.47.97.35) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: sisvmfb1HSQSVe_0rOUE8wfDquxi8grh X-Proofpoint-GUID: sisvmfb1HSQSVe_0rOUE8wfDquxi8grh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-28_16,2023-09-28_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=999 malwarescore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 mlxscore=0 clxscore=1015 suspectscore=0 bulkscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309280154 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: John Moon via Libabigail From: John Moon Reply-To: John Moon Cc: Trilok Soni , Satya Durga Srinivasu Prabhala Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" Currently, users are able to suppress changes to enumerator variants matching names specified in "changed_enumerators", but can't specify regular expressions. A common pattern when using enums is to have the final enum variant labeled as "*_MAX" or "*_LAST" so that users of the enum can have a way to determine how many variants there are. In these cases, when expanding an enum, the last variant will change, but that's an expected result that users may not want to flag as an ABI-breaking change. For example, if you have a change like this: enum foo { FOO, BAR, FOOBAR_MAX, }; ... enum foo { FOO, BAR, BAZ, FOOBAR_MAX, }; abidiff reports: 1 changed type unreachable from any public interface: [C] 'enum foo' changed: type size hasn't changed 1 enumerator insertion: 'foo::BAZ' value '2' 1 enumerator change: 'foo::FOOBAR_MAX' from value '2' to '3' at test_2.c:1:1 With a new changed_enumerators_regexp property, users can specify a suppression which stops abidiff from emitting this diff for any members which match the regular expressions in the list: [suppress_type] type_kind = enum changed_enumerators_regexp = .*_MAX$, .*_LAST$, .*_NUM$, .*_NBITS$ Signed-off-by: John Moon Signed-off-by: John Moon Signed-off-by: Dodji Seketeli --- include/abg-suppression.h | 6 +++ src/abg-suppression-priv.h | 1 + src/abg-suppression.cc | 84 +++++++++++++++++++++++++++++++++----- 3 files changed, 81 insertions(+), 10 deletions(-) -- 2.17.1 diff --git a/include/abg-suppression.h b/include/abg-suppression.h index 9449d06d..8fc6516d 100644 --- a/include/abg-suppression.h +++ b/include/abg-suppression.h @@ -330,6 +330,12 @@ public: void set_changed_enumerator_names(const vector&); + const vector& + get_changed_enumerator_regexp() const; + + void + set_changed_enumerator_regexp(const vector&); + virtual bool suppresses_diff(const diff* diff) const; diff --git a/src/abg-suppression-priv.h b/src/abg-suppression-priv.h index cf66a9f1..cc7b4b26 100644 --- a/src/abg-suppression-priv.h +++ b/src/abg-suppression-priv.h @@ -585,6 +585,7 @@ class type_suppression::priv string source_location_to_keep_regex_str_; mutable regex::regex_t_sptr source_location_to_keep_regex_; mutable vector changed_enumerator_names_; + mutable vector changed_enumerator_regexp_; priv(); diff --git a/src/abg-suppression.cc b/src/abg-suppression.cc index 4ed42e82..345b6e6f 100644 --- a/src/abg-suppression.cc +++ b/src/abg-suppression.cc @@ -770,6 +770,28 @@ void type_suppression::set_changed_enumerator_names(const vector& n) {priv_->changed_enumerator_names_ = n;} +/// Getter of the vector of the regular expression strings for changed +/// enumerators that are supposed to be suppressed. Note that this +/// will be "valid" only if the type suppression has the +/// 'type_kind = enum' property. +/// +/// @return the vector of the regular expression strings that are +/// supposed to match enumertor names to be suppressed. +const vector& +type_suppression::get_changed_enumerator_regexp() const +{return priv_->changed_enumerator_regexp_;} + +/// Setter of the vector of the regular expression strings for changed +/// enumerators that are supposed to be suppressed. Note that this +/// will be "valid" only if the type suppression has the +/// 'type_kind = enum' property. +/// +/// @param n the vector of the regular expression strings that are +/// supposed to match enumertor names to be suppressed. +void +type_suppression::set_changed_enumerator_regexp(const vector& n) +{priv_->changed_enumerator_regexp_ = n;} + /// Evaluate this suppression specification on a given diff node and /// say if the diff node should be suppressed or not. /// @@ -996,9 +1018,12 @@ type_suppression::suppresses_diff(const diff* diff) const // ... and yet carries some changed enumerators! && !enum_dif->changed_enumerators().empty()) { - // Make sure that all changed enumerators are listed in the - // vector of enumerator names returned by the - // get_changed_enumerator_names() member function. + + // Make sure that all changed enumerators are either: + // 1. listed in the vector of enumerator names returned + // by the get_changed_enumerator_names() member function + // 2. match a regular expression returned by the + // get_changed_enumerator_regexp() member function bool matched = true; for (string_changed_enumerator_map::const_iterator i = enum_dif->changed_enumerators().begin(); @@ -1006,13 +1031,20 @@ type_suppression::suppresses_diff(const diff* diff) const ++i) { matched &= true; - if (std::find(get_changed_enumerator_names().begin(), - get_changed_enumerator_names().end(), - i->first) == get_changed_enumerator_names().end()) - { - matched &= false; - break; - } + if ((std::find(get_changed_enumerator_names().begin(), + get_changed_enumerator_names().end(), + i->first) == get_changed_enumerator_names().end()) + && + (std::find_if(get_changed_enumerator_regexp().begin(), + get_changed_enumerator_regexp().end(), + [&] (const regex_t_sptr& enum_regexp) + { + return regex::match(enum_regexp, i->first); + }) == get_changed_enumerator_regexp().end())) + { + matched &= false; + break; + } } if (!matched) return false; @@ -2154,6 +2186,34 @@ read_type_suppression(const ini::config::section& section) changed_enumerator_names.push_back(p->get_value()->as_string()); } + /// Support 'changed_enumerators_regexp = .*_foo, bar_[0-9]+, baz' + /// + /// If the current type is an enum and if it carries changed + /// enumerators that match regular expressions listed in the + /// changed_enumerator_regexp property value then it should be + /// suppressed. + + ini::property_sptr changed_enumerators_regexp_prop = + section.find_property("changed_enumerators_regexp"); + + vector changed_enumerator_regexp; + if (changed_enumerators_regexp_prop) + { + if (ini::list_property_sptr p = + is_list_property(changed_enumerators_regexp_prop)) + { + for (string e : p->get_value()->get_content()) + changed_enumerator_regexp.push_back(regex::compile(e)); + } + else if (ini::simple_property_sptr p = + is_simple_property(changed_enumerators_prop)) + { + changed_enumerator_regexp.push_back( + regex::compile(p->get_value()->as_string()) + ); + } + } + if (section.get_name() == "suppress_type") result.reset(new type_suppression(label_str, name_regex_str, name_str)); else if (section.get_name() == "allow_type") @@ -2217,6 +2277,10 @@ read_type_suppression(const ini::config::section& section) && !changed_enumerator_names.empty()) result->set_changed_enumerator_names(changed_enumerator_names); + if (result->get_type_kind() == type_suppression::ENUM_TYPE_KIND + && !changed_enumerator_regexp.empty()) + result->set_changed_enumerator_regexp(changed_enumerator_regexp); + return result; }