From patchwork Mon Aug 25 11:43:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 382689 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 0F7461400A0 for ; Mon, 25 Aug 2014 21:43:53 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=k06R/unNa1YMF6z3OVNkAXI1Skvliu41FTOy22AONYW9ANNaqcdQE a1ClrkwLR/23FOq3WXPB4oIB1jZeGHS5b1aQKzVor0msuaGDMiLC3t8ynNPFwkBi 9rsYzlFc3SvLRLm0/dI2tdF1b6Gt8+vColxHzy+VOsmdck0tIZ3tt0= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=C7f157UDce7Cr39DcHDsdfxIlAw=; b=hEdZQRncOTvGyxwosh6n mU8Dv/JbAb8S9xTg6l8CKw5MFyhDNRQ0o79UbjqBnYHaME4cMYnX2v7OIbQLJZnA SFAcxHSTwTpd/6nabFAg7pc6aO6kJscfLPCPiWBaRLQ0KM7gFoQMrPoEnYuU0KQg PmMafgsWf5X9aByie0t5dW4= Received: (qmail 12252 invoked by alias); 25 Aug 2014 11:43:43 -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 12225 invoked by uid 89); 25 Aug 2014 11:43:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 25 Aug 2014 11:43:41 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s7PBhbuR009086 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 25 Aug 2014 07:43:38 -0400 Received: from redhat.com (ovpn-116-27.ams2.redhat.com [10.36.116.27]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s7PBhYLA016077 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Mon, 25 Aug 2014 07:43:36 -0400 Date: Mon, 25 Aug 2014 13:43:33 +0200 From: Marek Polacek To: GCC Patches , Jason Merrill , "Joseph S. Myers" Subject: [C/C++ PATCH] Allow __atomic_always_lock_free in a static assert (PR c/62024) Message-ID: <20140825114333.GI15033@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) PR62024 reports that we can't use __atomic_always_lock_free in a static assert, as the FEs say it's not a constant expression. Yet the docs say that the result of __atomic_always_lock_free is a compile time constant. We can fix this pretty easily. While fold folds __atomic_always_lock_free to a constant, that constant is wrapped in NOP_EXPR - and static assert code is unhappy. I think we can just STRIP_TYPE_NOPS - we don't expect an lvalue in the static assert code. This is done in both C and C++ FEs. What do you think? In C, we'd still pedwarn on such code, and in C++ we'd still reject non-constexpr functions that are not builtin functions. The tests require sync_char_short target in a hope they aren't run on targets where the static assert would actually trigger. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2014-08-25 Marek Polacek PR c/62024 c/ * c-parser.c (c_parser_static_assert_declaration_no_semi): Strip no-op conversions. cp/ * semantics.c (finish_static_assert): Strip no-op conversions. testsuite/ * g++.dg/cpp0x/pr62024.C: New test. * gcc.dg/pr62024.c: New test. Marek diff --git gcc/c/c-parser.c gcc/c/c-parser.c index d634bb1..fc7bbaf 100644 --- gcc/c/c-parser.c +++ gcc/c/c-parser.c @@ -2058,6 +2058,8 @@ c_parser_static_assert_declaration_no_semi (c_parser *parser) if (TREE_CODE (value) != INTEGER_CST) { value = c_fully_fold (value, false, NULL); + /* Strip no-op conversions. */ + STRIP_TYPE_NOPS (value); if (TREE_CODE (value) == INTEGER_CST) pedwarn (value_loc, OPT_Wpedantic, "expression in static assertion " "is not an integer constant expression"); diff --git gcc/cp/semantics.c gcc/cp/semantics.c index a54011f..b87d3ba 100644 --- gcc/cp/semantics.c +++ gcc/cp/semantics.c @@ -6870,6 +6870,9 @@ finish_static_assert (tree condition, tree message, location_t location, condition = cp_convert (boolean_type_node, condition, tf_warning_or_error); condition = maybe_constant_value (condition); + /* Strip no-op conversions. */ + STRIP_TYPE_NOPS (condition); + if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition)) /* Do nothing; the condition is satisfied. */ ; diff --git gcc/testsuite/g++.dg/cpp0x/pr62024.C gcc/testsuite/g++.dg/cpp0x/pr62024.C index e69de29..5f0640a 100644 --- gcc/testsuite/g++.dg/cpp0x/pr62024.C +++ gcc/testsuite/g++.dg/cpp0x/pr62024.C @@ -0,0 +1,7 @@ +// PR c/62024 +// { dg-do compile { target c++11 } } +// { dg-require-effective-target sync_char_short } + +int *p; +static_assert (__atomic_always_lock_free (1, p), ""); +static_assert (__atomic_always_lock_free (1, 0), ""); diff --git gcc/testsuite/gcc.dg/pr62024.c gcc/testsuite/gcc.dg/pr62024.c index e69de29..79a0b79 100644 --- gcc/testsuite/gcc.dg/pr62024.c +++ gcc/testsuite/gcc.dg/pr62024.c @@ -0,0 +1,8 @@ +/* PR c/62024 */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu11 -Wpedantic" } */ +/* { dg-require-effective-target sync_char_short } */ + +int *p; +_Static_assert (__atomic_always_lock_free (1, p), ""); /* { dg-warning "is not an integer constant" } */ +_Static_assert (__atomic_always_lock_free (1, 0), ""); /* { dg-warning "is not an integer constant" } */