From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by sourceware.org (Postfix) with ESMTPS id DAA5A385DC14 for ; Thu, 23 Jul 2020 19:39:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DAA5A385DC14 Received: by mail-io1-xd29.google.com with SMTP id t131so7512849iod.3 for ; Thu, 23 Jul 2020 12:39:19 -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:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=sezKCfFnzA4HubPqhOQJzVpbIcFk/10KnlSB0Kyp3hE=; b=pP9qLRdjdynmAeLG2S1eMcMqKcKi32Ra+8orTYijgoxU4HLUo2Ft+zA4Eu1Eg+C/8f 75GSFVvvPW6WTy4OvpqR+w33i3tDeNxhrxzs5hdTnvhuluSWq160AUGfwR7xdPC91LeE +KsyArjV+5I78h8gHRL6FcSgRPsh+pXo1R6lQObzCyZ6V9SUXxd+BTLrrMcjm9RWAsJE B+AK/cYqNX4Sx0AIt7sGIBZwhgLYjqZgEhpG0Fs7AQv2Z21fc9Jv7sK5F6YEpWYAXWLh HFG+37Z696bc3XbqQhppp3L4+VK0ZkpBMy+8eL1sDJV20pov6eUK2uTbb1HdnxDcdkIy A26A== X-Gm-Message-State: AOAM531Tm/RrJtrhJp5q8/Ly38rKX/niAeEmo51Rn5LgzmjHkki35WMQ chd8TtOzogwIaP7M7H9SZGMUD4pBLZTr/Byn+J8= X-Google-Smtp-Source: ABdhPJyPh1y5iP1KF7oJEMldCqbZqrR0NV8V/Nq4rgfLJ0qlc+DxUcvI+PLHOHByL39YgTeBo5nssyk4pONos1e/Kp4= X-Received: by 2002:a02:9469:: with SMTP id a96mr3773657jai.121.1595533159218; Thu, 23 Jul 2020 12:39:19 -0700 (PDT) MIME-Version: 1.0 References: <55B7EE1A-B14C-44F5-B32A-41A5368D5E00@purdue.edu> In-Reply-To: <55B7EE1A-B14C-44F5-B32A-41A5368D5E00@purdue.edu> From: Jonathan Wakely Date: Thu, 23 Jul 2020 20:39:08 +0100 Message-ID: Subject: Re: Confirm the semantic of GCC extension "Conditionals with Omitted Operands" To: "Gong, Sishuai" Cc: "gcc-help@gcc.gnu.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, 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: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jul 2020 19:39:21 -0000 On Thu, 23 Jul 2020 at 20:24, Gong, Sishuai via Gcc-help wrote: > > Hi, > > I=E2=80=99d like to follow-up on my previous email. > > What exactly is the semantic of the GCC extension =E2=80=9CConditionals w= ith Omitted Operands=E2=80=9D? Does it guarantee that the read operations o= f the first operand are only made once (which is not what happens in our ex= periments)? If not, is there a way to guarantee that the reads of the first= operand are only made once to avoid concurrency problems (e.g., a double r= ead that sees different results because of a write made by a concurrent thr= ead)? Did you read the previous replies? To make a variable safe for concurrent access by multiple t threads you need to use atomic operations, and there is no atomic version of the ?: operator. So you will need to do something like: unsigned int hello(int *const *a) { int b; __atomic_load(a, &, __ATOMIC_SEQ_CST); unsigned int c =3D b; return c & 0xFE ?: 0x123; } In other words, if the GCC extension doesn't provide the guarantees you need, do something different.