From patchwork Thu Mar 16 21:13:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 739993 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vkh7435Pnz9s0Z for ; Fri, 17 Mar 2017 08:14:22 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="oD0M0Khy"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; q=dns; s=default; b=SLQyXuxGVy+BkKL /VIIlfm79qiTSTyV4REZuVAwB+28kgh4gXC06/+sJGyth99yBazRmw3pYYJW3dG/ Oh5R/rrcMiRiwqpkfV9/2bvwfLSo6l4kN1n6jTqUD5DqkxiB1szJqPXpjLMaBMUO BHtLAEqYXrztk4n65WzADG6hmhqg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; s=default; bh=5jaSARf7FcKzN+t6NX3fR 1cYFcg=; b=oD0M0KhyiilVQ079VUZpTlUCGF/nYa3ZEdgdXcblXr99NCIiUu3YB y6TiuFGx23L4OzrlN8pkjsllufj6ikZk4VkItwsvbsPwMcAvwVmpEpWYJ+tsWEdZ 5p08AvemoOjFAErmGclfq3emvXYJ99bBBikADovimGh2QLHzZqjZuM= Received: (qmail 29088 invoked by alias); 16 Mar 2017 21:14:13 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 29065 invoked by uid 89); 16 Mar 2017 21:14:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-23.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.2 spammy= X-HELO: mail-ot0-f169.google.com Received: from mail-ot0-f169.google.com (HELO mail-ot0-f169.google.com) (74.125.82.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 16 Mar 2017 21:14:10 +0000 Received: by mail-ot0-f169.google.com with SMTP id a12so1376429ota.0 for ; Thu, 16 Mar 2017 14:14:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=AF9zw9V1VQChuzRFiRB5osRXWu9MLYLva1WfRNYaqm0=; b=fgbYJ6Onu6fcI4ZJBFjlTD96tjEJ7IGmzQGTJ3NcmrcDVz3s9+cRdqiu087YSGXjyA BjyqMka9eH3ZV2iJjtSDVuyBvHH11O1w6TZMTT8kturOPIWjbtDm/Gu6wXFnBjMmh16I 4A+gBjhrzf4ap4mfLkFwMnekUIQpPq1fGxJIU+ohhar+/a/hnj2vERdNrLmJ0+w0FcyH vXndYG/vSCAFYHBA4kmMS/PsCZwpxp80fCy3ke10NMe0xivD0rDGS/ruqR/MnhW3q5d5 6/+kLFhL1cw1ARCEmzpKxsQWIr8X79ScDCJ5Qxi9riPR103W0qb6ug9BAIycvkQ4a+6j oqOw== X-Gm-Message-State: AFeK/H3zO55IbM0Fsko+ZyA5ek6eNv46iWTIdWQG+8sSYxD2AU1+UXG22hMeT8H44kxIJQ9PBPPpJEp8tAEByHxI X-Received: by 10.157.52.102 with SMTP id v93mr5773520otb.61.1489698850074; Thu, 16 Mar 2017 14:14:10 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.187.8 with HTTP; Thu, 16 Mar 2017 14:13:49 -0700 (PDT) In-Reply-To: <20170309154732.GA23961@redhat.com> References: <20170309154732.GA23961@redhat.com> From: Jason Merrill Date: Thu, 16 Mar 2017 17:13:49 -0400 Message-ID: Subject: Re: [PATCH] Define std::byte for C++17 (P0298R3) To: Jonathan Wakely Cc: "libstdc++" , gcc-patches List X-IsSubscribed: yes On Thu, Mar 9, 2017 at 10:47 AM, Jonathan Wakely wrote: > This is a new type for C++17, with no impact on anything in non-C++17 > dialects. This is intentionally only defined in and not > . And this patch adds the aliasing semantics: Tested x86_64-pc-linux-gnu, applying to trunk. commit cc516c1009e5a68dadeb29bd74f1d2fa13e64e95 Author: Jason Merrill Date: Thu Mar 16 13:37:08 2017 -0400 * decl.c (start_enum): std::byte aliases anything. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 0ecd30b..61ecf81 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -14079,6 +14079,12 @@ start_enum (tree name, tree enumtype, tree underlying_type, { enumtype = cxx_make_type (ENUMERAL_TYPE); enumtype = pushtag (name, enumtype, /*tag_scope=*/ts_current); + + /* std::byte aliases anything. */ + if (enumtype != error_mark_node + && TYPE_CONTEXT (enumtype) == std_node + && !strcmp ("byte", TYPE_NAME_STRING (enumtype))) + TYPE_ALIAS_SET (enumtype) = 0; } else enumtype = xref_tag (enum_type, name, /*tag_scope=*/ts_current, diff --git a/gcc/testsuite/g++.dg/cpp1z/byte1.C b/gcc/testsuite/g++.dg/cpp1z/byte1.C new file mode 100644 index 0000000..51c1a33 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/byte1.C @@ -0,0 +1,31 @@ +// Test for std::byte aliasing properties. +// { dg-options "-std=c++1z -O3" } + +#include + +using byte = std::byte; + +enum class notbyte: unsigned char {} *np; + +int main() +{ + int x; + + /* Stores through byte* can alias int, so the compiler can't optimize + "x != 0". */ + byte *p = (byte*)&x; + x = 42; + for (int i = 0; i < 4; ++i) + p[i] = byte(0); + if (x != 0) + __builtin_abort(); + + /* Stores through notbyte* mustn't alias int, so at -O3 the compiler should + optimize "x != 42" to false. */ + notbyte *np = (notbyte*)&x; + x = 42; + for (int i = 0; i < 4; ++i) + np[i] = notbyte(0); + if (x != 42) + __builtin_abort(); +}