From patchwork Wed Apr 29 15:19:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lyon X-Patchwork-Id: 1279475 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=ZtddoKyf; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49C2Hf5hftz9sP7 for ; Thu, 30 Apr 2020 01:19:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9C397395B057; Wed, 29 Apr 2020 15:19:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C397395B057 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1588173573; bh=BwUXmXkMzr6WK7Dl2J1htV1IsODymc/PHi9gA9tGYpM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ZtddoKyfxCA2ATBjoeMx4vuwWFUIsLoXK9nxbvBMNsDdfo6lcame9fWkvBTZ440sf iNS8V6FCvF/sL5r81/Fi0J01w7Bi8igN1jFP2B1hTcyNGR9tfWCL64awxuzPa53IW8 OnRKEschuAPO46mYPYm5kVUpItgRiHxu/zU/6ufA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by sourceware.org (Postfix) with ESMTPS id D160D389366B for ; Wed, 29 Apr 2020 15:19:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D160D389366B Received: by mail-wr1-x443.google.com with SMTP id j2so2995926wrs.9 for ; Wed, 29 Apr 2020 08: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:from:to:subject:date:message-id:in-reply-to :references; bh=BwUXmXkMzr6WK7Dl2J1htV1IsODymc/PHi9gA9tGYpM=; b=m9zx2Xn0EJHIqBr6L8RPBld7jghcP6Wg+WddwgVylF3cJHCaaoaVFn7OUxP2opNcc3 UOSjA5D9jPUJqGqdg2w7qMf/orsfeFnmNSCg+H1ZOnaIzGE3r7Z5WcYkXF7LVjChyW6o p56JO4lB5ug8nT1vDOw2KysSVaOTfb5MKbu5H92/F2idcOyVNzvnCHtZWTvYQ3++Bmdl fGcvkcwI2zc6uuY0s5REgwi3ro3IzTLTBr2/fZV4gtShkxZsYg/J1AnsQPg4rk7EIE4F i4RxEO/iRtx377JO5curVQyjGl8JWeHUL/NNESxZMkX7wXKDE/WwQeqZm3ilfAjcofRK /Cwg== X-Gm-Message-State: AGi0PuY6qgGzEbLQF6bE+Wm4WhrKq0CmMd+MZVj8e1ocQirygDL5FzAY rr/u4fcH3GwPhVvRsp7i1kdkUmb8YMg= X-Google-Smtp-Source: APiQypKQB56ILNSP2PfTEONCUNweh6UGJze9i2pgdQ4wdeE6+hS5yMWXvOM5RSX/L2xjVR6jKINhRA== X-Received: by 2002:adf:8284:: with SMTP id 4mr39782115wrc.6.1588173555321; Wed, 29 Apr 2020 08:19:15 -0700 (PDT) Received: from localhost.localdomain (static.42.136.251.148.clients.your-server.de. [148.251.136.42]) by smtp.gmail.com with ESMTPSA id c83sm8739226wmd.23.2020.04.29.08.19.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Apr 2020 08:19:14 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] arm: Warn if IRQ handler is not compiled with -mgeneral-regs-only [PR target/94743] Date: Wed, 29 Apr 2020 15:19:12 +0000 Message-Id: <1588173552-10417-2-git-send-email-christophe.lyon@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1588173552-10417-1-git-send-email-christophe.lyon@linaro.org> References: <1588173552-10417-1-git-send-email-christophe.lyon@linaro.org> X-Spam-Status: No, score=-24.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, 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-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Christophe Lyon via Gcc-patches From: Christophe Lyon Reply-To: Christophe Lyon Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" The interrupt attribute does not guarantee that the FP registers are saved, which can result in problems difficult to debug. Saving the FP registers and status registers can be a large penalty, so it's probably not desirable to do that all the time. If the handler calls other functions, we'd likely need to save all of them, for lack of knowledge of which registers they actually use. This is even more obscure for the end-user when the compiler inserts calls to helper functions such as memcpy (some multilibs do use FP registers to speed it up). In the PR, we discussed adding routines in libgcc to save the FP context and saving only locally-clobbered FP registers, but I think this is too intrusive for stage 4. In the mean time, emit a warning to suggest re-compiling with -mgeneral-regs-only. Note that this can lead to errors if the code uses floating-point and -mfloat-abi=hard, eg: argument of type 'double' not permitted with -mgeneral-regs-only This can be troublesome for the user, but at least this would make them aware of the latent issue. The patch adds two testcases: - pr94734-1.c checks that a warning is emitted. One function can make implicit calls to runtime floating-point routines, the other one doesn't. We can improve the diagnostic later not to warn in the second case. - pr94734-2.c checks that no warning is emitted when using -mgeneral-regs-only. 2020-04-29 Christophe Lyon PR target/94743 gcc/ * config/arm/arm.c (arm_handle_isr_attribute): Warn if -mgeneral-regs-only is not used. gcc/testsuite/ * gcc.target/arm/pr94743-1.c: New test. * gcc.target/arm/pr94743-2.c: New test. --- gcc/config/arm/arm.c | 5 +++++ gcc/testsuite/gcc.target/arm/pr94743-1.c | 20 ++++++++++++++++++++ gcc/testsuite/gcc.target/arm/pr94743-2.c | 17 +++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 gcc/testsuite/gcc.target/arm/pr94743-1.c create mode 100644 gcc/testsuite/gcc.target/arm/pr94743-2.c diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 6a6e804..34aad1d 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -7176,6 +7176,11 @@ arm_handle_isr_attribute (tree *node, tree name, tree args, int flags, name); *no_add_attrs = true; } + else if (TARGET_VFP_BASE) + { + warning (OPT_Wattributes, "FP registers might be clobbered despite %qE attribute: compile with -mgeneral-regs-only", + name); + } /* FIXME: the argument if any is checked for type attributes; should it be checked for decl ones? */ } diff --git a/gcc/testsuite/gcc.target/arm/pr94743-1.c b/gcc/testsuite/gcc.target/arm/pr94743-1.c new file mode 100644 index 0000000..67700c6 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/pr94743-1.c @@ -0,0 +1,20 @@ +/* PR target/94743 */ +/* { dg-do compile } */ + +typedef struct { + double fpdata[32]; +} dummy_t; + +dummy_t global_d; +dummy_t global_d1; + +__attribute__ ((interrupt("IRQ"))) void IRQ_HDLR_Test(void) +{ /* { dg-warning { FP registers might be clobbered despite 'interrupt' attribute: compile with -mgeneral-regs-only} "" { target *-*-* } . } */ + global_d.fpdata[3] += global_d.fpdata[3] * global_d1.fpdata[3]; +} + + +__attribute__ ((interrupt("IRQ"))) void IRQ_HDLR_Test2(void) +{ /* { dg-warning { FP registers might be clobbered despite 'interrupt' attribute: compile with -mgeneral-regs-only} "" { target *-*-* } . } */ + global_d.fpdata[3] = 1.0; +} diff --git a/gcc/testsuite/gcc.target/arm/pr94743-2.c b/gcc/testsuite/gcc.target/arm/pr94743-2.c new file mode 100644 index 0000000..745fd36 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/pr94743-2.c @@ -0,0 +1,17 @@ +/* PR target/94743 */ +/* { dg-do compile } */ +/* { dg-options "-mgeneral-regs-only" } */ + +typedef struct { + /* Do not use floating-point types, which are not be compatible with + -mgeneral-regs-only under -mfloat-abi=hard */ + int fpdata[32]; +} dummy_t; + +dummy_t global_d; +dummy_t global_d1; + +__attribute__ ((interrupt("IRQ"))) void IRQ_HDLR_Test(void) +{ + global_d.fpdata[3] += global_d.fpdata[3] * global_d1.fpdata[3]; +}