From patchwork Tue Feb 27 21:42:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 86484 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 D43073858415 for ; Tue, 27 Feb 2024 21:43:23 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by sourceware.org (Postfix) with ESMTPS id CDF413858C5E for ; Tue, 27 Feb 2024 21:42:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CDF413858C5E Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CDF413858C5E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::12f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709070143; cv=none; b=ji2Y/aeuC6SVxaQvir4FQX0bYRwG/Vcc4r3xyxlQ7L0ApAk6JyiZGHR8RLvyJvD3VGxGz3Q1rKBvOuh5xgygVt02jeKKePRfwC+b1s74HZ4VQBEottw+XtjZWlMNARDNCqLaf061UTayVTD7ZyiB26R9VwagUIQmjtMJlQSCq4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709070143; c=relaxed/simple; bh=4NxKL3Ucvs9cJHjAd5lirHiZl1bLHj4zfKF5JKvq25c=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=n/5nJha4DYH4DNE7KTuCGLYwDAm0B1PEO1bFUaIItHnpvs0SiADftfx+ZYXBmWwHfcZHYQ2JaKeQhCqPGp5bdt62f0O92oXZ3o2R+w7E97qgK/1GdW6/Vf+AtWEsAOxdRJoGBo2u0JeHNndnusZ7jUIbu6f25B9c/dQA8US0f6U= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x12f.google.com with SMTP id e9e14a558f8ab-3657dbe2008so16087475ab.1 for ; Tue, 27 Feb 2024 13:42:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1709070141; x=1709674941; darn=sourceware.org; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=pLfUQn+nT3Yp81ZCcoOgVEBbLzfuJUXPwn0lR0TTcd4=; b=IZ9UG9uiFlgBcfkMfNt1cRpgTU/yRMu6kg6atNo9c6c+X5prbMkVbUd+Ty2YtgKqQo 4m8AbYiOx0bBPEV3luCphB2ZTueDStd4kTS8A2HaFZ7DtasF+LlBXNCkJ0JGqcrKoQnD LxoOY8jIxEz+RrW93tEKhISplO5iktwpSEryLqBCff+ZJowkKAmx/zM3JjFJNNELeLmX aW4IIOfURgCT143UYSveO+8+hSdhSjmr+N/Pm0Oo4pRC496yq0FGHQanJrqm6iZgvuR8 1e/x/v/PZZBoomEBiKruZuc+jJveiyNhLoWp5ewll8l7ZqaFXEizp8DDQ2LA5/+dfBQc Nyvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709070141; x=1709674941; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pLfUQn+nT3Yp81ZCcoOgVEBbLzfuJUXPwn0lR0TTcd4=; b=qHktIqHW8djMjZeRaND3UTMsri7jFHLOVirymw81zm8zVVjtAsHhBXFW/ocD3fhIc5 bljrKAEmrd48+FdjgVSum+qzs/J3RQq5UdI2tfXMCVhOtxg1yUfPJh/UZOGBScQKS/1Z 8RSo9o7uJv6uaXKrOurl3zDhMLDWs4bM0bnGTOcFX8mHCEkWWEusz0Rq5peTCTigHQLk 9OAiCDlR5MF8/8xk3HcLZ0oY78vTUi/qTiQZGcjL+ESkOduV2FVusfw8kk4LBwcExfYV 3kD2eZW1iZPQgCX0zo2QmUUVW/YDElTJugxSFNTmBGa1wIjFI5nqDPgVfMkSoeu+I6bT n2Gw== X-Gm-Message-State: AOJu0YyFEQ7D27xQ0gvKTxNJWc5ar4Cab+2+UDawu5bUouf0XRKKiPxD vpnd6U13XVF1xvFe4Hr0BDRHYlaujqIKTCDVrHoX/DT3hyWcRicqSZcG/jWxWuL4/gLfAn0e/zw = X-Google-Smtp-Source: AGHT+IGYqCMEWrHAeUzEUql2E6qGXENH/gCuGB8PVu3xZYZ4lo9FmVnr5NJXLnymu3L2SMwLN16VgQ== X-Received: by 2002:a92:cd0d:0:b0:365:1749:cae0 with SMTP id z13-20020a92cd0d000000b003651749cae0mr13771883iln.7.1709070140931; Tue, 27 Feb 2024 13:42:20 -0800 (PST) Received: from localhost.localdomain (71-211-170-195.hlrn.qwest.net. [71.211.170.195]) by smtp.gmail.com with ESMTPSA id gh4-20020a056638698400b0047438454db4sm1983600jab.9.2024.02.27.13.42.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 13:42:20 -0800 (PST) From: Tom Tromey Date: Tue, 27 Feb 2024 14:42:19 -0700 Subject: [PATCH 3/3] Require trivial destructor in allocate_on_obstack MIME-Version: 1.0 Message-Id: <20240227-obstac-alloc-v1-3-bd079aad35cd@adacore.com> References: <20240227-obstac-alloc-v1-0-bd079aad35cd@adacore.com> In-Reply-To: <20240227-obstac-alloc-v1-0-bd079aad35cd@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This patch makes allocate_on_obstack a little bit safer, by enforcing the rule that objects allocated on an obstack must have a trivial destructor. The static assert is done in a method -- doing it inside the class itself won't work because the class is incomplete at that point. --- gdb/addrmap.h | 2 +- gdb/block.c | 2 +- gdb/block.h | 2 +- gdb/dwarf2/cooked-index.h | 2 +- gdb/gdbtypes.h | 4 ++-- gdb/symtab.h | 2 +- gdbsupport/gdb_obstack.h | 6 +++++- 7 files changed, 12 insertions(+), 8 deletions(-) diff --git a/gdb/addrmap.h b/gdb/addrmap.h index 0d61046cebd..55dea36b877 100644 --- a/gdb/addrmap.h +++ b/gdb/addrmap.h @@ -81,7 +81,7 @@ struct addrmap_mutable; /* Fixed address maps. */ struct addrmap_fixed : public addrmap, - public allocate_on_obstack + public allocate_on_obstack { public: diff --git a/gdb/block.c b/gdb/block.c index 079053cd79e..6d0d33fa85e 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -31,7 +31,7 @@ C++ files, namely using declarations and the current namespace in scope. */ -struct block_namespace_info : public allocate_on_obstack +struct block_namespace_info : public allocate_on_obstack { const char *scope = nullptr; struct using_direct *using_decl = nullptr; diff --git a/gdb/block.h b/gdb/block.h index 4c29f6599ef..ae676c4ba67 100644 --- a/gdb/block.h +++ b/gdb/block.h @@ -105,7 +105,7 @@ struct blockranges This implies that within the body of one function the blocks appear in the order of a depth-first tree walk. */ -struct block : public allocate_on_obstack +struct block : public allocate_on_obstack { /* Return this block's start address. */ CORE_ADDR start () const diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 928c4ef655c..0d4fcb8538e 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -104,7 +104,7 @@ extern bool language_requires_canonicalization (enum language lang); This is an "open" class and the members are all directly accessible. It is read-only after the index has been fully read and processed. */ -struct cooked_index_entry : public allocate_on_obstack +struct cooked_index_entry : public allocate_on_obstack { cooked_index_entry (sect_offset die_offset_, enum dwarf_tag tag_, cooked_index_flag flags_, diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 435a040544a..f80bd7e071a 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -211,7 +211,7 @@ struct variant_part; control other variant parts as well. This struct corresponds to DW_TAG_variant in DWARF. */ -struct variant : allocate_on_obstack +struct variant : allocate_on_obstack { /* * The discriminant ranges for this variant. */ gdb::array_view discriminants; @@ -243,7 +243,7 @@ struct variant : allocate_on_obstack and holds an array of variants. This struct corresponds to DW_TAG_variant_part in DWARF. */ -struct variant_part : allocate_on_obstack +struct variant_part : allocate_on_obstack { /* * The index of the discriminant field in the outer type. This is an index into the type's array of fields. If this is -1, there diff --git a/gdb/symtab.h b/gdb/symtab.h index 5bd63979132..d49b7066e3a 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -1244,7 +1244,7 @@ extern gdb::array_view symbol_impls; /* This structure is space critical. See space comments at the top. */ -struct symbol : public general_symbol_info, public allocate_on_obstack +struct symbol : public general_symbol_info, public allocate_on_obstack { symbol () /* Class-initialization of bitfields is only allowed in C++20. */ diff --git a/gdbsupport/gdb_obstack.h b/gdbsupport/gdb_obstack.h index 20f888660f9..7b3bb05bc00 100644 --- a/gdbsupport/gdb_obstack.h +++ b/gdbsupport/gdb_obstack.h @@ -133,14 +133,18 @@ struct auto_obstack : obstack { obstack_free (this, obstack_base (this)); } }; -/* Objects are allocated on obstack instead of heap. */ +/* Objects are allocated on obstack instead of heap. This is a mixin + that uses CRTP to ensure that the type in question is trivially + destructible. */ +template struct allocate_on_obstack { allocate_on_obstack () = default; void* operator new (size_t size, struct obstack *obstack) { + static_assert (IsFreeable::value); return obstack_alloc (obstack, size); }