From patchwork Fri Mar 31 01:44:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9655397 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DFA1760352 for ; Fri, 31 Mar 2017 01:46:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1E4228688 for ; Fri, 31 Mar 2017 01:46:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6CDC28693; Fri, 31 Mar 2017 01:46:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8140428696 for ; Fri, 31 Mar 2017 01:46:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934769AbdCaBqr (ORCPT ); Thu, 30 Mar 2017 21:46:47 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:34258 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935019AbdCaBqq (ORCPT ); Thu, 30 Mar 2017 21:46:46 -0400 Received: by mail-wr0-f193.google.com with SMTP id w43so16583279wrb.1 for ; Thu, 30 Mar 2017 18:46:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QNbZ0TjWq77eaFrn0SkKIF3t3s7SX9PTc8LI4+s/oO0=; b=E7v37n+aIjxYdrSUFEAAlEkmxeE0ozIvSaj7gBcKdsjS8N0VYojmIOR+bvNTDeAyxW vZWdRibEiMLRSYAyyXD+h+FNmeOSqUodRg4QE6HufJQc7KSK0ktaVtbpG2bGSfOiL83g rxiSIua6aWOBIUNY5Zk0qp93xNz6cl4O146cC+t5Y1sL8aWJ3dvy+5TOJvUekhPNnLxP d3C//ES3kd0WTQNc46X2nX7TWXNU1w4fQDJaVXTfE1q7s/Y84pJVvVhvX93z/cWbBiGx isFjjB537lvwuUuO00hKHb4AJFKgeobLEXB/Cl6xPd7wuyNM6ybya+EztQ9ofUi9blEo au2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QNbZ0TjWq77eaFrn0SkKIF3t3s7SX9PTc8LI4+s/oO0=; b=QXnM17swwM0BZZdeDg4f9NZ4mjXTyjdcTLydVqplaq5D9Q20gs9ZkSEgyz4y6sa2Os H1Ba8NJ1SybGgTPOz6JJMUoC6b6IkAOln1T4DETr8AFnEdqinzL+d0e1Z7uVLMZl+foI 8ReXUZrzmNjhbKTPq/VLRDCRhQ4Kz2XQhRCJP8dig8DEpxRYPRZ9pVtE/FsQTZFY3+J/ N0mAkrCRIIqM00JuOirjZ4vU5iR1OrrUMtQYi3qZRN+yTY0agkzT4E0du2QnNkw0fPrm VSQUIeWZKPpAMamAI8MIDLVfKN6vsyg0QtIFa6cOxmQ9nYYfvtpYZMbDBBUW63rKZ1ZJ VKqQ== X-Gm-Message-State: AFeK/H2uU1zCu9HuePocftyvebxhXtpbILw4QVnAQjjkWdxYW/VHqAIgLxWXdxKCxGb7jQ== X-Received: by 10.28.111.3 with SMTP id k3mr408014wmc.39.1490924804077; Thu, 30 Mar 2017 18:46:44 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:88d:1900:cdad:92b8:5279:ae19]) by smtp.gmail.com with ESMTPSA id 189sm917023wmm.31.2017.03.30.18.46.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Mar 2017 18:46:43 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Nicolai Stange , Luc Van Oostenryck Subject: [PATCH v4 17/25] constexpr: recognize references to labels as address constants Date: Fri, 31 Mar 2017 03:44:51 +0200 Message-Id: <20170331014459.9351-18-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170331014459.9351-1-luc.vanoostenryck@gmail.com> References: <20170331014459.9351-1-luc.vanoostenryck@gmail.com> Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Nicolai Stange As an extension, GCC allows labels to be referenced a la label1: ... void *ptr = &&label1; Tag these label references as being address constants allowing them to be used as initializers for objects of static storage duration. Signed-off-by: Nicolai Stange Signed-off-by: Luc Van Oostenryck --- expression.c | 1 + validation/constexpr-labelref.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 validation/constexpr-labelref.c diff --git a/expression.c b/expression.c index 00edd1f99..241ab7bad 100644 --- a/expression.c +++ b/expression.c @@ -681,6 +681,7 @@ static struct token *unary_expression(struct token *token, struct expression **t sym->ctype.modifiers |= MOD_ADDRESSABLE; add_symbol(&function_computed_target_list, sym); } + label->flags = CEF_ADDR; label->label_symbol = sym; *tree = label; return token->next->next; diff --git a/validation/constexpr-labelref.c b/validation/constexpr-labelref.c new file mode 100644 index 000000000..15b5293ae --- /dev/null +++ b/validation/constexpr-labelref.c @@ -0,0 +1,14 @@ +static void a(void) +{ +label1: + ; + static void *b = &&label1; +} + +/* + * check-name: label reference constness verification. + * check-command: sparse -Wconstexpr-not-const $file + * + * check-error-start + * check-error-end + */