From patchwork Mon Apr 15 11:28:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1923692 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=MJK5qoVn; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=WOcYaD0e; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=MJK5qoVn; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=WOcYaD0e; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VJ4fw5VsJz1yZ2 for ; Mon, 15 Apr 2024 21:28:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E3F053858408 for ; Mon, 15 Apr 2024 11:28:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id 3AA5C3858D32 for ; Mon, 15 Apr 2024 11:28:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3AA5C3858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3AA5C3858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713180483; cv=none; b=Y5VlonW8T1w7AznryemKY8IFqaLvXc8O315NcP0fS39/lTHjSt+g9lR9+bjpO1TPqnlaQEHesjJuN02ALm3fk4JEs2qqim+nXMcK2EIHiHHtilU1k/b3E5xCEmwHxZlWUlJv9aIg0Sajf05dz59rVQUx8iVbDI0ILYFFcSknRbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713180483; c=relaxed/simple; bh=Z38Xy4eGn3XoZPVyt5hNrUeYbeTbuPSqEuY/dohjIVQ=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=uSA64ekwKKvaQTsD/lsbrZTbGa761NAVxhUJ8NyEryO4W6ozZDuu89bBaYKZ2Fd8WJ6uLdZYJ2zRfwYxFFGz2s09UD8DC9Rcip3rIPEw97F3dF3G0PeRUhGCYvALL6lL9evPSJGjihQUwYeatBI0SyQi3yCtzO7K7xhFH0F/smo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.5.241] (unknown [10.168.5.241]) (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 smtp-out2.suse.de (Postfix) with ESMTPS id 32FA25CEBA; Mon, 15 Apr 2024 11:28:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1713180480; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=+nhGI54FKziGjp/EeyywfPhR8csry8r5/uIBX3+BKWQ=; b=MJK5qoVnVs+DktceF0wpNRHrLZzhjFGVk33XnsM6nceG+CeyRHXe75PwNdj1941Kpq9zCY gOs7NT+Ur5wYzOHoPUPBX2GeWrjPXgtP4riWDqxmGGdmX+DkhnyINE5d34XuZlRm5vfoJA 2CKXSEMgks2SVBBGfpuBfG5t9rkyKyE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1713180480; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=+nhGI54FKziGjp/EeyywfPhR8csry8r5/uIBX3+BKWQ=; b=WOcYaD0eM7GUrD/aGj63LzydkYFp92FAvQZaS4etzmO+X6laVGk/Vvflnf2UDHI0tO0+uz jHuWaGHoOorrROCg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1713180480; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=+nhGI54FKziGjp/EeyywfPhR8csry8r5/uIBX3+BKWQ=; b=MJK5qoVnVs+DktceF0wpNRHrLZzhjFGVk33XnsM6nceG+CeyRHXe75PwNdj1941Kpq9zCY gOs7NT+Ur5wYzOHoPUPBX2GeWrjPXgtP4riWDqxmGGdmX+DkhnyINE5d34XuZlRm5vfoJA 2CKXSEMgks2SVBBGfpuBfG5t9rkyKyE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1713180480; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=+nhGI54FKziGjp/EeyywfPhR8csry8r5/uIBX3+BKWQ=; b=WOcYaD0eM7GUrD/aGj63LzydkYFp92FAvQZaS4etzmO+X6laVGk/Vvflnf2UDHI0tO0+uz jHuWaGHoOorrROCg== Date: Mon, 15 Apr 2024 13:28:00 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: Jakub Jelinek Subject: [PATCH] gcov-profile/114715 - missing coverage for switch MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-1.79 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MISSING_MID(2.50)[]; NEURAL_HAM_LONG(-1.00)[-0.996]; NEURAL_HAM_SHORT(-0.20)[-0.990]; MIME_GOOD(-0.10)[text/plain]; MISSING_XM_UA(0.00)[]; RCVD_COUNT_ZERO(0.00)[0]; ARC_NA(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; FROM_HAS_DN(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_DN_SOME(0.00)[] X-Spam-Score: -1.79 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Message-Id: <20240415112822.E3F053858408@sourceware.org> The following avoids missing coverage for the line of a switch statement which happens when gimplification emits a BIND_EXPR wrapping the switch as that prevents us from setting locations on the containing statements via annotate_all_with_location. Instead set the location of the GIMPLE switch directly. Bootstrapped and tested on x86_64-unknown-linux-gnu, OK for trunk? Thanks, Richard. PR gcov-profile/114715 * gimplify.cc (gimplify_switch_expr): Set the location of the GIMPLE switch. * gcc.misc-tests/gcov-24.c: New testcase. --- gcc/gimplify.cc | 1 + gcc/testsuite/gcc.misc-tests/gcov-24.c | 30 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 gcc/testsuite/gcc.misc-tests/gcov-24.c diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index 3df58b962f3..26e96ada4c7 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -3017,6 +3017,7 @@ gimplify_switch_expr (tree *expr_p, gimple_seq *pre_p) switch_stmt = gimple_build_switch (SWITCH_COND (switch_expr), default_case, labels); + gimple_set_location (switch_stmt, EXPR_LOCATION (switch_expr)); /* For the benefit of -Wimplicit-fallthrough, if switch_body_seq ends with a GIMPLE_LABEL holding SWITCH_BREAK_LABEL_P LABEL_DECL, wrap the GIMPLE_SWITCH up to that GIMPLE_LABEL into a GIMPLE_BIND, diff --git a/gcc/testsuite/gcc.misc-tests/gcov-24.c b/gcc/testsuite/gcc.misc-tests/gcov-24.c new file mode 100644 index 00000000000..395099bd7ae --- /dev/null +++ b/gcc/testsuite/gcc.misc-tests/gcov-24.c @@ -0,0 +1,30 @@ +/* { dg-options "-fprofile-arcs -ftest-coverage" } */ +/* { dg-do run { target native } } */ + +int main() +{ + int a = 1; + int b = 2; + int c = -3; + switch(a) /* count(1) */ + { + case 1: /* count(1) */ + c = 3; + switch(b) { /* count(1) */ + case 1: /* count(#####) */ + c = 4; + break; + case 2: /* count(1) */ + c = 5; + break; + } + break; + case 2: /* count(#####) */ + c = 6; + break; + default: /* count(#####) */ + break; + } +} + +/* { dg-final { run-gcov gcov-24.c } } */