From patchwork Sun May 27 13:19:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jozef Lawrynowicz X-Patchwork-Id: 921097 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-478583-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mittosystems.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="jQ3fQ+7N"; dkim-atps=neutral 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 40v0vl2fcSz9s1d for ; Sun, 27 May 2018 23:19:44 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=J13rQHRtTm2Uot6IzavPK3UQ9UqgkmAqpanT1Sq40d18hgzeLJ Fib94Ilb/2wAGNm7WtmkX97o7S9qGy+6eVIBpIUwtWZOTOSRGL78mBusyEgJInK5 h8DAYaY0QUVX2Ucltdp9WS4g3WNf9bUrxc9ZAOm71ofMFDEjf7So36mok= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=93Pu7SU4Ub3cGElkRAkek6kGs0g=; b=jQ3fQ+7Nk2Db/a6kS4xc dJimPYqU8Xd4WzMjrfqcuHgkFDoI62nZKNmDf8cQkdq6WYs0R1SufqR2MiEwHFG4 2maAoF0ZIgqwvlifjdk9A3UeflLI4fJNyyk80qtc9cu4rO/qFcUI0DcxbPm1+jor sEft1R18oJ2I3i9OML/ewlk= Received: (qmail 56772 invoked by alias); 27 May 2018 13:19:27 -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 56732 invoked by uid 89); 27 May 2018 13:19:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=declaring, sk:__inter, 1111, Ensure X-HELO: mail-wr0-f180.google.com Received: from mail-wr0-f180.google.com (HELO mail-wr0-f180.google.com) (209.85.128.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 27 May 2018 13:19:17 +0000 Received: by mail-wr0-f180.google.com with SMTP id j1-v6so16169979wrm.1 for ; Sun, 27 May 2018 06:19:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language; bh=b9GxeNn8AcPA0HCDTuwHbk1pI7gT6eU5GuncGTMrFFI=; b=QbStYGGc4aFs302pucGwwyJJVYehJposiQsgr1SqXgBncsQ53/wzs9ItMxZr/w6VJy H+BuyEauSJIfa9AIN4thMbq4Ba1PC3/8MJAvmDtM8kpDvLuSZLQ8+JoATXELgbL5qZgx XAG43U+103S5/L619K0s9opFne5eN5eNc3v2r7lucgt5NaDcBgBN4e0ZzLvDuQhfzoky Kz63esQToxQ7r5Iyx/cHM53r8246Aj5RD0E+BrSvlWFw6QQ/phO6+Rm3VGhcjkyrbolr tzibgTTFfhchh+/JC/wb4M/0+5tB5wa1cyW4emA9K6tSmEz+oCgCapvG/7P/sYtwiya+ kwpw== X-Gm-Message-State: ALKqPwc9nYn8ySYMIx6w8bwbzB2vIm9AchAf9wLgrFZeRWkZyWJlxGLm D2nMui09oaN4usoPUzXBgzVsJQ== X-Google-Smtp-Source: AB8JxZqVbxTfENyS/dL7QgusVmSLD9fJMNyqQ1JwZGSVmL4UBTXS2knHx6RukBgbg3iVTyitx4zkGQ== X-Received: by 2002:adf:ad2f:: with SMTP id p44-v6mr8131850wrc.164.1527427155040; Sun, 27 May 2018 06:19:15 -0700 (PDT) Received: from ?IPv6:2a00:23c5:e05:e600:f1d2:1112:ff41:c518? ([2a00:23c5:e05:e600:f1d2:1112:ff41:c518]) by smtp.gmail.com with ESMTPSA id b72-v6sm15773789wmf.11.2018.05.27.06.19.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 May 2018 06:19:14 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Nick Clifton , dj Delorie From: Jozef Lawrynowicz Subject: [PATCH] [MSP430] Allow interrupt handers to be static and fix __interrupt__ attribute causing an ICE Message-ID: <7e90fb25-64b7-ffc6-cf9f-49b0fe388038@mittosystems.com> Date: Sun, 27 May 2018 14:19:13 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 Some users have a preference for declaring interrupt handlers as static functions, as this enforces that interrupts should not be called directly (from other source files at least). This patch allows interrupt handlers to be declared as static and also fixes an assertion failure when the interrupt attribute is written with the leading and trailing underscores included in the name. Successfully regtested gcc testsuite on trunk for msp430-elf in the -mcpu=msp430x/-mlarge variation. If the patch is acceptable, I would appreciate if someone would commit it for me, as I don't have write access. From 18d1980bb4061cee9d97f2b7737af2dfd9e52c34 Mon Sep 17 00:00:00 2001 From: Jozef Lawrynowicz Date: Sun, 27 May 2018 12:55:41 +0100 Subject: [PATCH] MSP430: Allow interrupt handlers to be static and fix the __interrupt__ attribute causing an ICE 2018-05-27 Jozef Lawrynowicz * gcc/config/msp430/msp430.md (msp430_attr): Allow interrupt handlers to be static and remove check on interrupt attribute name. gcc/testsuite/gcc.target/msp430/ * function-attributes-4.c: New test. * static-interrupts.c: New test. --- gcc/config/msp430/msp430.c | 17 ++-- .../gcc.target/msp430/function-attributes-4.c | 111 +++++++++++++++++++++ .../gcc.target/msp430/static-interrupts.c | 26 +++++ 3 files changed, 144 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/gcc.target/msp430/function-attributes-4.c create mode 100644 gcc/testsuite/gcc.target/msp430/static-interrupts.c diff --git a/gcc/config/msp430/msp430.c b/gcc/config/msp430/msp430.c index a8fed12..85626a2 100644 --- a/gcc/config/msp430/msp430.c +++ b/gcc/config/msp430/msp430.c @@ -1867,11 +1867,9 @@ msp430_attr (tree * node, { gcc_assert (DECL_P (* node)); + /* Only the interrupt attribute takes an argument. */ if (args != NULL) { - /* Only the interrupt attribute takes an argument. */ - gcc_assert (TREE_NAME_EQ (name, ATTR_INTR)); - tree value = TREE_VALUE (args); switch (TREE_CODE (value)) @@ -1916,13 +1914,12 @@ msp430_attr (tree * node, if (TREE_CODE (TREE_TYPE (* node)) == FUNCTION_TYPE && ! VOID_TYPE_P (TREE_TYPE (TREE_TYPE (* node)))) message = "interrupt handlers must be void"; - - if (! TREE_PUBLIC (* node)) - message = "interrupt handlers cannot be static"; - - /* Ensure interrupt handlers never get optimised out. */ - TREE_USED (* node) = 1; - DECL_PRESERVE_P (* node) = 1; + else + { + /* Ensure interrupt handlers never get optimised out. */ + TREE_USED (* node) = 1; + DECL_PRESERVE_P (* node) = 1; + } } else if (TREE_NAME_EQ (name, ATTR_REENT)) { diff --git a/gcc/testsuite/gcc.target/msp430/function-attributes-4.c b/gcc/testsuite/gcc.target/msp430/function-attributes-4.c new file mode 100644 index 0000000..07d13c9 --- /dev/null +++ b/gcc/testsuite/gcc.target/msp430/function-attributes-4.c @@ -0,0 +1,111 @@ +/* { dg-do compile } */ +/* Check that the foo interrupt vectors aren't actually removed. */ +/* { dg-final { scan-assembler-times "__interrupt_vector_foo" 2 } } */ + +/* Check that warnings are emitted when attributes are used incorrectly and + that attributes are interpreted correctly whether leading and trailing + underscores are used or not. */ + +void __attribute__((__naked__,__reentrant__)) +fn1(void) +{ /* { dg-warning "naked functions cannot be reentrant" } */ +} + +void __attribute__((naked,reentrant)) +fn2(void) +{ /* { dg-warning "naked functions cannot be reentrant" } */ +} + +void __attribute__((__reentrant__,__naked__)) +fn3(void) +{ /* { dg-warning "reentrant functions cannot be naked" } */ +} + +void __attribute__((reentrant,naked)) +fn4(void) +{ /* { dg-warning "reentrant functions cannot be naked" } */ +} + +void __attribute__((__critical__,__reentrant__)) +fn5(void) +{ /* { dg-warning "critical functions cannot be reentrant" } */ +} + +void __attribute__((critical,reentrant)) +fn6(void) +{ /* { dg-warning "critical functions cannot be reentrant" } */ +} + +void __attribute__((__reentrant__,__critical__)) +fn7(void) +{ /* { dg-warning "reentrant functions cannot be critical" } */ +} + +void __attribute__((reentrant,critical)) +fn8(void) +{ /* { dg-warning "reentrant functions cannot be critical" } */ +} + +void __attribute__((__critical__,__naked__)) +fn9(void) +{ /* { dg-warning "critical functions cannot be naked" } */ +} + +void __attribute__((critical,naked)) +fn10(void) +{ /* { dg-warning "critical functions cannot be naked" } */ +} + +void __attribute__((__naked__,__critical__)) +fn11(void) +{ /* { dg-warning "naked functions cannot be critical" } */ +} + +void __attribute__((naked,critical)) +fn12(void) +{ /* { dg-warning "naked functions cannot be critical" } */ +} + +int __attribute__((interrupt)) +isr1 (void) +{ /* { dg-warning "interrupt handlers must be void" } */ +} + +int __attribute__((__interrupt__)) +isr2 (void) +{ /* { dg-warning "interrupt handlers must be void" } */ +} + +void __attribute__((interrupt("foo1"))) +isr3 (void) +{ /* { dg-warning "unrecognized interrupt vector argument" } */ +} + +void __attribute__((__interrupt__("foo2"))) +isr4 (void) +{ /* { dg-warning "unrecognized.*interrupt vector argument" } */ +} + +void __attribute__((interrupt(65))) +isr5 (void) +{ /* { dg-warning "numeric argument of 'interrupt' attribute must be in range 0..63" } */ +} + +void __attribute__((__interrupt__(100))) +isr6 (void) +{ /* { dg-warning "numeric argument of 'interrupt' attribute must be in range 0..63" } */ +} + +void __attribute__((interrupt(0.5))) +isr7 (void) +{ /* { dg-warning "argument of 'interrupt' attribute is not a string constant or number" } */ + volatile int __attribute__((__naked__)) + a; /* { dg-warning "'naked' attribute only applies to functions" } */ +} + +void __attribute__((__interrupt__(1.5))) +isr8 (void) +{ /* { dg-warning "argument of 'interrupt' attribute is not a string constant or number" } */ + volatile int __attribute__((naked)) + a; /* { dg-warning "'naked' attribute only applies to functions" } */ +} diff --git a/gcc/testsuite/gcc.target/msp430/static-interrupts.c b/gcc/testsuite/gcc.target/msp430/static-interrupts.c new file mode 100644 index 0000000..06d9ea6 --- /dev/null +++ b/gcc/testsuite/gcc.target/msp430/static-interrupts.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-Os" } */ +/* { dg-final { scan-assembler-times "__interrupt_vector_" 4 } } */ + +/* Test that interrupts aren't optimised out and that "__interrupt__" and + "interrupt" can be used interchangeably. */ + +static void __attribute__((interrupt(1))) +isr_static (void) +{ +} + +static void __attribute__((__interrupt__(2))) +isr_static_alt (void) +{ +} + +void __attribute__((interrupt(3))) +isr_global (void) +{ +} + +void __attribute__((__interrupt__(4))) +isr_global_alt (void) +{ +} -- 2.7.4