From patchwork Tue Oct 27 17:20:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 40897 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 A9A99386F46A; Tue, 27 Oct 2020 17:20:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A9A99386F46A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1603819236; bh=KMoC8OIdJ+EMQZvkLnLaRR92YqWoBYnXSRd302LxDas=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Help: List-Subscribe:From:Reply-To:Cc:From; b=vNroKWM+pDEgyucEp7rhiCY7bkoYfYwB9YoNBu16p3yJGQl1j65Capcqaqf5ODycE Od+0zWCzhdcqZF0GtnRcrNts/gyFzyAkjxhV5cFw8QQTaThYPpAhRU9CAutPIOy8OK V6SOzDLfeNcSAomtcBiWwRDihUBoT8frHDwU7HzQ= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 10ED73857C6C for ; Tue, 27 Oct 2020 17:20:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 10ED73857C6C Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-159-vip1DVJkPOuF41El_0aHtA-1; Tue, 27 Oct 2020 13:20:30 -0400 X-MC-Unique: vip1DVJkPOuF41El_0aHtA-1 Received: by mail-wr1-f71.google.com with SMTP id t3so1031155wrq.2 for ; Tue, 27 Oct 2020 10:20:30 -0700 (PDT) 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:organization:date:message-id :user-agent:mime-version; bh=KMoC8OIdJ+EMQZvkLnLaRR92YqWoBYnXSRd302LxDas=; b=HfJ7KqKonUwgN6Kk4touBKKw426msKWa9nkc/LIoKugiSO96kAJdTaTCPzJjqdlsXS 5/D6m4s8m0lHmWgSc0RX0XOC0GmOvbhLxHg/Xyql3nR5dNpL7CALUf0MAymsGdx79oiB eKioHb93HFJAC/9/gdgdt8soWdnAfoTlwOSbYtmd39IlMfEvzYbaFlsXM0aIBe4+oc0e k2ZfFUjeZVD4m0tRPnsuTTqSP3sXRnw9u8H8sroP2LufdtrqTUSxvsMx1E1nJIWBF9dL vxFbf21ssQRy2HjDFeth8KBsyLPtqFhemu2ksZKCQ/qW8e4ISvwDg7X22g3K1Xgwnrk1 m2Hw== X-Gm-Message-State: AOAM533k0yAFQvZMm2yL+cSlw3US+RiBHkS7Yl+NcAWvGtZmOHQEaxa+ LaQ+4sWLBlupJcFRjhqReQfXM6Av+MuEhZUI3avKsVRn5ScIjOH7OMg6BkYdlHJ6yz5KJOX4X4H HY26cIt/B2AtNplAadbn2 X-Received: by 2002:a1c:bb84:: with SMTP id l126mr3721737wmf.141.1603819227931; Tue, 27 Oct 2020 10:20:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYvZgval4BQXhhFFZjHU9gXpW69uAd7P4ITIDF5VYst3W/sz0bOYd7clpx8uCYznMOrtmtCw== X-Received: by 2002:a1c:bb84:: with SMTP id l126mr3721708wmf.141.1603819227448; Tue, 27 Oct 2020 10:20:27 -0700 (PDT) Received: from localhost (91-166-131-65.subs.proxad.net. [91.166.131.65]) by smtp.gmail.com with ESMTPSA id b63sm2695420wme.9.2020.10.27.10.20.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 10:20:24 -0700 (PDT) Received: by localhost (Postfix, from userid 1000) id 688C45800FC; Tue, 27 Oct 2020 18:20:20 +0100 (CET) To: Giuliano Procida Subject: [PATCH] Bug PR26739 - Handle qualified typedef array types Organization: Red Hat / France X-Operating-System: Fedora 34 X-URL: http://www.redhat.com Date: Tue, 27 Oct 2020 18:20:20 +0100 Message-ID: <878sbra8mj.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: Dodji Seketeli via Libabigail From: Dodji Seketeli Reply-To: Dodji Seketeli Cc: libabigail@sourceware.org Errors-To: libabigail-bounces@sourceware.org Sender: "Libabigail" Hello, CV-qualifiers of a typedef of an array type apply to the elements of the array. So this can be transformed into a typedef of array type which element type is similarly CV-qualified. That transformation helps avoiding spurious changes that might occur when comparing the latter form against the former even though both are equivalent. This patch performs that transformation, just like we already do for CV-qualified array types which are transformed into an array of similarly CV-qualified elements. * include/abg-fwd.h (is_typedef_of_array): Declare new function. (peel_qualified_or_typedef_type): Declare new overload. * src/abg-dwarf-reader.cc (maybe_strip_qualification): Handle qualified typedef of arrays. * src/abg-ir.cc (peel_qualified_or_typedef_type): Define new overload for type_base_sptr. * tests/data/test-diff-filter/test-PR26739-report-0.txt: New reference test output. * tests/data/test-diff-filter/test-PR26739-v{0,1}.c: Source code of new binary test input. * tests/data/test-diff-filter/test-PR26739-v{0,1}.o: New binary test inputs. * tests/data/Makefile.am: Add the new test material above to source distribution. * tests/test-diff-filter.cc (in_out_specs): Add the test inputs above to this harness. Signed-off-by: Dodji Seketeli --- include/abg-fwd.h | 6 ++ src/abg-dwarf-reader.cc | 27 +++++++++ src/abg-ir.cc | 57 ++++++++++++++++++ tests/data/Makefile.am | 5 ++ .../test-PR26739-report-0.txt | 3 + tests/data/test-diff-filter/test-PR26739-v0.c | 8 +++ tests/data/test-diff-filter/test-PR26739-v0.o | Bin 0 -> 2976 bytes tests/data/test-diff-filter/test-PR26739-v1.c | 12 ++++ tests/data/test-diff-filter/test-PR26739-v1.o | Bin 0 -> 2920 bytes tests/test-diff-filter.cc | 7 +++ 10 files changed, 125 insertions(+) create mode 100644 tests/data/test-diff-filter/test-PR26739-report-0.txt create mode 100644 tests/data/test-diff-filter/test-PR26739-v0.c create mode 100644 tests/data/test-diff-filter/test-PR26739-v0.o create mode 100644 tests/data/test-diff-filter/test-PR26739-v1.c create mode 100644 tests/data/test-diff-filter/test-PR26739-v1.o diff --git a/include/abg-fwd.h b/include/abg-fwd.h index 4b09929c..36c73f7a 100644 --- a/include/abg-fwd.h +++ b/include/abg-fwd.h @@ -708,6 +708,9 @@ is_array_of_qualified_element(type_base_sptr&); qualified_type_def_sptr is_array_of_qualified_element(const array_type_def_sptr&); +array_type_def_sptr +is_typedef_of_array(const type_base_sptr&); + void set_data_member_offset(var_decl_sptr, uint64_t); @@ -848,6 +851,9 @@ peel_qualified_type(const type_base_sptr&); type_base* peel_qualified_or_typedef_type(const type_base* type); +type_base_sptr +peel_qualified_or_typedef_type(const type_base_sptr &type); + type_base_sptr peel_typedef_pointer_or_reference_type(const type_base_sptr); diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index 7257052e..45f3cf62 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -14342,6 +14342,33 @@ maybe_strip_qualification(const qualified_type_def_sptr t, // delayed until after all editing is done. ABG_ASSERT_NOT_REACHED; } + else if (array_type_def_sptr array = is_typedef_of_array(u)) + { + // We should not be editing types that are already canonicalized. + ABG_ASSERT(!array->get_canonical_type()); + type_base_sptr element_type = array->get_element_type(); + + if (qualified_type_def_sptr qualified = is_qualified_type(element_type)) + { + // We should not be editing types that are already canonicalized. + ABG_ASSERT(!qualified->get_canonical_type()); + qualified_type_def::CV quals = qualified->get_cv_quals(); + quals |= t->get_cv_quals(); + qualified->set_cv_quals(quals); + result = is_decl(u); + } + else + { + qualified_type_def_sptr qual_type + (new qualified_type_def(element_type, + t->get_cv_quals(), + t->get_location())); + add_decl_to_scope(qual_type, is_decl(element_type)->get_scope()); + array->set_element_type(qual_type); + ctxt.schedule_type_for_late_canonicalization(is_type(qual_type)); + result = is_decl(u); + } + } return result; } diff --git a/src/abg-ir.cc b/src/abg-ir.cc index 8c04797f..5e5937a5 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -5813,6 +5813,35 @@ peel_qualified_or_typedef_type(const type_base* type) return const_cast(type); } +/// Return the leaf underlying type of a qualified or typedef type. +/// +/// If the underlying type is itself a qualified or typedef type, then +/// recursively return the first underlying type of that qualified or +/// typedef type to return the first underlying type that is not a +/// qualified or typedef type. +/// +/// If the underlying type is NOT a qualified nor a typedef type, then +/// just return that underlying type. +/// +/// @param type the qualified or typedef type to consider. +/// +/// @return the leaf underlying type. +type_base_sptr +peel_qualified_or_typedef_type(const type_base_sptr &t) +{ + type_base_sptr type = t; + while (is_typedef(type) || is_qualified_type(type)) + { + if (typedef_decl_sptr t = is_typedef(type)) + type = peel_typedef_type(t); + + if (qualified_type_def_sptr t = is_qualified_type(type)) + type = peel_qualified_type(t); + } + + return type; +} + /// Return the leaf underlying or pointed-to type node of a @ref /// typedef_decl, @ref pointer_type_def or @ref reference_type_def /// node. @@ -8646,6 +8675,34 @@ is_array_of_qualified_element(type_base_sptr& type) return array_type_def_sptr(); } +/// Test if a type is a typedef of an array. +/// +/// Note that the function looks through qualified and typedefs types +/// of the underlying type of the current typedef. In other words, if +/// we are looking at a typedef of a CV-qualified array, or at a +/// typedef of a CV-qualified typedef of an array, this function will +/// still return TRUE. +/// +/// @param t the type to consider. +/// +/// @return true if t is a typedef which underlying type is an array. +/// That array might be either cv-qualified array or a typedef'ed +/// array, or a combination of both. +array_type_def_sptr +is_typedef_of_array(const type_base_sptr& t) +{ + array_type_def_sptr result; + + if (typedef_decl_sptr typdef = is_typedef(t)) + { + type_base_sptr u = + peel_qualified_or_typedef_type(typdef->get_underlying_type()); + result = is_array_type(u); + } + + return result; +} + /// Test if a type is an array_type_def::subrange_type. /// /// @param type the type to consider. diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index 40a575fa..db9a8e36 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -888,6 +888,11 @@ test-diff-filter/test-PR26309-v1.c \ test-diff-filter/test-PR26309-v0.o \ test-diff-filter/test-PR26309-v1.o \ test-diff-filter/test-PR26309-report-0.txt \ +test-diff-filter/test-PR26739-v0.c \ +test-diff-filter/test-PR26739-v1.c \ +test-diff-filter/test-PR26739-v0.o \ +test-diff-filter/test-PR26739-v1.o \ +test-diff-filter/test-PR26739-report-0.txt \ \ test-diff-suppr/test0-type-suppr-v0.cc \ test-diff-suppr/test0-type-suppr-v1.cc \ diff --git a/tests/data/test-diff-filter/test-PR26739-report-0.txt b/tests/data/test-diff-filter/test-PR26739-report-0.txt new file mode 100644 index 00000000..9666a8fd --- /dev/null +++ b/tests/data/test-diff-filter/test-PR26739-report-0.txt @@ -0,0 +1,3 @@ +Functions changes summary: 0 Removed, 0 Changed (1 filtered out), 0 Added function +Variables changes summary: 0 Removed, 0 Changed, 0 Added variable + diff --git a/tests/data/test-diff-filter/test-PR26739-v0.c b/tests/data/test-diff-filter/test-PR26739-v0.c new file mode 100644 index 00000000..e9148ac4 --- /dev/null +++ b/tests/data/test-diff-filter/test-PR26739-v0.c @@ -0,0 +1,8 @@ +typedef const int immutable[7]; +typedef immutable monster; + +struct A { + monster q; +}; + +void fun(struct A * a) { (void) a; } diff --git a/tests/data/test-diff-filter/test-PR26739-v0.o b/tests/data/test-diff-filter/test-PR26739-v0.o new file mode 100644 index 0000000000000000000000000000000000000000..5a4ae08f964055b0a411d330d9f3ba3d727a7b89 GIT binary patch literal 2976 zcmbVO&2Jk;6o2Ej<4ra(NlYOoJ#0mxjnrM+X`4DlDJ~IBA}SO`RB)h**7n$5@UDZs zt`ZPJLKUbIhgL#DNZhy~4oDohBJmG!ucqLJQKc=v;}y)|b9|twhRJPEpP*0n9#wvB)o6pu{Og& zKJM&k#OX&ApUd^a{AZcXxv3kdkie-Ubxal>{hKDlJx_!2Y{zGFLT;cWjSSJAy3D|y zOCtl~KAaF4Fg<}0U?de!$PAd9z!H7zpA<4+;^}}FQEyS%hw+_%{6(fGVO-%1`cbQu zkqD=%UcevGLNbBGxmcgl@CRaD5;L8YdMYc5zIy(yf>Yej#rmd(izVFF@I|ryLd<$x zStI426FM}_3trdX`XAgDIMt-q1@7=D!0y928YFX9auGj_z@=UTw=o=oJK#OfZSlsa zv+sxPKFVU=YcvM@&Iz$M@WKv1Y0~pUE=@25xXpeLaC~*#upe<3+twLIUh{q7hUNNuiKwP8Qq(wwXdSB?vujF z_&?D?Azk+Z%IKqBS9FN|EBVsHLxI!1B1qnG{BXszfurt|1Q`K-7i%34y6!HDbd0pW z7hvVsH0E?&sxvMB-$YYLd&-|)J3apvV!BU+;CBJOLkop;-F=j$#g~6k7iTYC| Ty?*kWW?vKef2$fJuiO6zTQuNz literal 0 HcmV?d00001 diff --git a/tests/data/test-diff-filter/test-PR26739-v1.c b/tests/data/test-diff-filter/test-PR26739-v1.c new file mode 100644 index 00000000..5c31e40c --- /dev/null +++ b/tests/data/test-diff-filter/test-PR26739-v1.c @@ -0,0 +1,12 @@ +typedef int plain[7]; +typedef const plain monster; + +struct A { + monster q; +}; + +void fun(struct A * a) { + (void) a; + // assignment to read-only location + // a->q[0] = 0; +} diff --git a/tests/data/test-diff-filter/test-PR26739-v1.o b/tests/data/test-diff-filter/test-PR26739-v1.o new file mode 100644 index 0000000000000000000000000000000000000000..9966762568f70b7ac8f631b4c8ba904f7557a9c5 GIT binary patch literal 2920 zcmbtV-D@0G6hC)oH#^BBYmzmZHGP;;Z5wcAcB4(xYU(0ABe}`~BQJG1E=|on3mLlig zz`;6x2K^==Zx%^g$QObz#xWAhEjY-Em+@y_gkvmk4pE%^09e7gjuOCBdlUjQ$F<1} z?3-^Kr8q^IoB_j>W@{L2%4M%rBy_4mY3qw$ zzFr|?tDqR?76GQ8!qgNOUZldQWWd}C$w?|uB3{M60c-eY>|tpJ|H;1MUNG3%U0FT* z(mAI;iv2Kl;)5H!#oLY_MgD$hr7V`XW7zp(Y%98c?@y-h?0%CSem_++nAZS zga#>``KOM^!-K!Gl(@)QFmC2}GY;tu)MSw%+E3RRX+P;OMoD@u1D`yC5n!Y`QuM6-2vknPGOw!b%3(WL^#drRs4wNQU(%#PK*~c z{4+7G2u?et?#i-aukL?c!PV8gqT%ym{E^^#d^s1Yvmk7U%?eq!-~1Qc7C65x=e)EvpkNmL154-e& zkV_X#0d8~9?{mCP+;9+c7dz7##(wjC5r}v9+L7PqqVWI8me8NpO0K62R~N$gyooW{ zs&pI&gz24kSv68*-TxHo=zRQF{~G%0F)5wQ{{sya(rxK6p~tzd*pT>Z`eMT$0;h9D zkUY!yA|*txv>uZb4-zfFPl8LP+wP!3$H?|;0am4>;JPi%Gpqi)qA8?5)lavYUVjTQ zJtji%n*iUYfkL|N9_q64|1R>&b)x*#?|S|lh*3;gCyEK35Y70D1O%7)C8zr#%l}W| z?>)xX3g@Mc~?Y|QKhwcuU6kN_d|vk r>>W}6jwqP!b$X3-f7+9*sotfckf=XZ(&tZcv;5_S^1bSevhM#6w{_d% literal 0 HcmV?d00001 diff --git a/tests/test-diff-filter.cc b/tests/test-diff-filter.cc index b3b1e91b..8d90b13e 100644 --- a/tests/test-diff-filter.cc +++ b/tests/test-diff-filter.cc @@ -773,6 +773,13 @@ InOutSpec in_out_specs[] = "data/test-diff-filter/test-PR26309-report-0.txt", "output/test-diff-filter/test-PR26309-report-0.txt", }, + { + "data/test-diff-filter/test-PR26739-v0.o", + "data/test-diff-filter/test-PR26739-v1.o", + "--no-default-suppression", + "data/test-diff-filter/test-PR26739-report-0.txt", + "output/test-diff-filter/test-PR26739-report-0.txt", + }, // This should be the last entry {NULL, NULL, NULL, NULL, NULL} };