From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 8DBB43858D1E for ; Fri, 5 Jan 2024 19:39:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8DBB43858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8DBB43858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704483555; cv=none; b=Qq6i5CRriwVVAuMcBUug7E8ADcXx1h88yOeYeJxDlV2+1meD7cMaCxzgiWBf6GJctymmM5E4B0ucrG4uj6/FEIRh4HefIzJFTWva+sQVou0dPMxR1/ic+CaWee2a3pbMPHDM4ABGSrp6bwNjpDyw+xjhd1VTRvFJMK54FVI6qOs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704483555; c=relaxed/simple; bh=Wt8rrhp86gu5s1J2gqJ2g0HJp6v/ukNC3RJQcRE9BZM=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=r6eDU+pqSwet1Vi6PKIjVSHJJX+8jIhG/YTNwl8BL34eEVNXmz33OkwZhpitMgRMN2COiTatIa0KGyV7/d5YAsd4WPoTzAQp/0YBA+f/IfASYjRQnmBGDchcBlSRgXa4Cu9yU6cqnAq5Na/F5z7xy4xPioQFeqbJBJ8Z/ZOhbCQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704483551; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RAJRzNjijEMLndIK+YRql8LdQqwIgNxdjj5aWfR8Z8Q=; b=SyMbZmaTOBu7rSeb4vjH29wmAJXIvjzOOe+c099iB5pncL8F2DvnmGeYlW85/J1dS+KrbT KtLXFi6AAwCNHKzWb4cxkyKNyPRfc8DxeMat78WWIpHF7UE7Pwq6Pu8ZuSqLTAO2K8BwFZ s7TWmHcwSsupti+1hGb0yqruJhp4kxo= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-664-MwjKu7AhOdSkMVTLBs7WKg-1; Fri, 05 Jan 2024 14:39:09 -0500 X-MC-Unique: MwjKu7AhOdSkMVTLBs7WKg-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-427f6c85c35so24103011cf.3 for ; Fri, 05 Jan 2024 11:39:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704483549; x=1705088349; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=MmJmqfvMEuyA3/s4DrFCscfJ4CBb3YhsPpmbjlc5/tQ=; b=N6MHhNKbj17SwYCdQNsxzieeZSh/bUc2F0s8fAgfK/SrySmmi8qqV7f1cLz2nhUJYf DcEz/JU18XtJKIWQE5OB3nJJFZr8a8n7aqV9FvE2OSk28bEfE5YTV5z+MG9tXgvfkxL0 aegthQR70TRdfbGZsUO6FddjucuiDm41ew/Fnnl79ccZu648NPugZiKxhOcp5UT8KZqD Lw31Mvbibau4wFpNzoPPsFybxZzLF0pu8yMbgQ7p0VchrtwfCpqcbbMM4LZm398NP1PA L1w8qHGmlP2GU21iQ3JW/o079v53z+IhcoiJOvuWA+FIczhZOdwRNDYZLfMy0ZKVT9hp jgxQ== X-Gm-Message-State: AOJu0YyCAWawbJrb17+49QTt9svHx/wisImf+ehM4ijCtoxcFJM6Khcd x/d+T1uc9sp43oEsUmuYDa+kUBY0d0Mu3DxDerxW740CKYnkIWhH7/iAa/FVukCnZQKPNYSr5Cl rjd+RMN/m27XFlt4= X-Received: by 2002:a05:622a:304:b0:429:7ffb:1dc1 with SMTP id q4-20020a05622a030400b004297ffb1dc1mr53323qtw.22.1704483549333; Fri, 05 Jan 2024 11:39:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IF3uF+C3jUWYJXZohTVvKrzJeoyo5h6wa4CrnM9llK7urBZhGZzC0qwf+FyVkTh6A/6J816EA== X-Received: by 2002:a05:622a:304:b0:429:7ffb:1dc1 with SMTP id q4-20020a05622a030400b004297ffb1dc1mr53315qtw.22.1704483548960; Fri, 05 Jan 2024 11:39:08 -0800 (PST) Received: from t14s.localdomain (c-76-28-97-5.hsd1.ma.comcast.net. [76.28.97.5]) by smtp.gmail.com with ESMTPSA id kl12-20020a05622a2c4c00b004283403bb77sm989684qtb.36.2024.01.05.11.39.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 11:39:08 -0800 (PST) Message-ID: Subject: Re: [PATCH] libgccjit: Add support for setting the comment ident From: David Malcolm To: Antoni Boucher , "jit@gcc.gnu.org" , "gcc-patches@gcc.gnu.org" Date: Fri, 05 Jan 2024 14:39:07 -0500 In-Reply-To: <0c37a2a72b2e3a5f85844d27f8d59c21d10ca7f6.camel@zoho.com> References: <0c37a2a72b2e3a5f85844d27f8d59c21d10ca7f6.camel@zoho.com> User-Agent: Evolution 3.44.4 (3.44.4-2.fc36) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_SORBS_WEB,SPF_HELO_NONE,SPF_NONE,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 List-Id: On Fri, 2024-01-05 at 12:09 -0500, Antoni Boucher wrote: > Hi. > This patch adds support for setting the comment ident (analogous to > #ident "comment" in C). > Thanks for the review. Thanks for the patch. This may sound like a silly question, but what does #ident do and what is it used for? FWIW I found this in our documentation: https://gcc.gnu.org/onlinedocs/cpp/Other-Directives.html [...snip...] > +Output options > +************** > + > +.. function:: void gcc_jit_context_set_output_ident (gcc_jit_context *ct= xt,\ > + const char* output_= ident) > + > + Set the identifier to write in the .comment section of the output fil= e to > + ``output_ident``. Analogous to: ...but only on some targets, according to the link above. Maybe add that link here? > + > + .. code-block:: c > + > + #ident "My comment" > + > + in C. > + > + This entrypoint was added in :ref:`LIBGCCJIT_ABI_26`; you can test fo= r > + its presence using Can the param "output_ident" be NULL? It isn't checked for NULL in the patch's implementation of gcc_jit_context_set_output_ident, and recording::output_ident's constructor does check for it being NULL... > + > + .. code-block:: c > + > + #ifdef LIBGCCJIT_HAVE_gcc_jit_context_set_output_ident > diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc > index dddd537f3b1..243a9fdf972 100644 > --- a/gcc/jit/jit-playback.cc > +++ b/gcc/jit/jit-playback.cc > @@ -319,6 +319,13 @@ get_type (enum gcc_jit_types type_) > return new type (type_node); > } > =20 > +void > +playback::context:: > +set_output_ident (const char* ident) > +{ > + targetm.asm_out.output_ident (ident); > +} > + ...but looking at varasm.cc's default_asm_output_ident_directive it looks like the param must be non-NULL. So this should either be conditionalized here to: if (ident) targetm.asm_out.output_ident (ident); or else we should ensure that "ident" is non-NULL at the API boundary and document this. My guess is that it doesn't make sense to have a NULL ident, so we should go with the latter approach. Can you have more than one #ident directive? Presumably each one just adds another line to the generated asm, right? [...snip...] > @@ -2185,6 +2192,52 @@ recording::string::write_reproducer (reproducer &) > /* Empty. */ > } > =20 > +/* The implementation of class gcc::jit::recording::output_ident. */ > + > +/* Constructor for gcc::jit::recording::output_ident, allocating a > + copy of the given text using new char[]. */ > + > +recording::output_ident::output_ident (context *ctxt, const char *ident) > +: memento (ctxt) > +{ > + m_ident =3D ident ? xstrdup (ident) : NULL; > +} > + > +/* Destructor for gcc::jit::recording::output_ident. */ > + > +recording::output_ident::~output_ident () > +{ > + delete[] m_ident; m_ident is allocated above using xstrdup, so it must be cleaned up with "free"; I don't think it's safe to use "delete[]" here. [...snip...] > +/* Implementation of recording::memento::write_reproducer for output_ide= nt. */ > + > +void > +recording::output_ident::write_reproducer (reproducer &r) > +{ > + r.write (" gcc_jit_context_set_output_ident (%s, \"%s\");", > +=09 r.get_identifier (get_context ()), > +=09 m_ident); It isn't safe on all implementations to use %s with m_ident being NULL. [...snip...] Thanks again for the patch; hope this is constructive Dave