From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D57E13858D20; Fri, 3 Feb 2023 15:12:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D57E13858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675437146; bh=u9RLfSdKR6PwTVMtizzYjD429hlL2XERENLlJnnuhxI=; h=From:To:Subject:Date:From; b=qtm2xLTwwZCj6WWyRGUHMrc5/3v6lwAgRt9TD4UUCVs4wvREenvNvVAonAuRUTRjr s4204y1wUhPEkg+rXYqBXxrIuo+BTZHDSnbSKoHhnGWoB7L4Re/Wv8g4z5T9nhNP5D eBVFsDjlIROhxGWOnGl31JcS9DBNd01bIB1FZ7mo= From: "sebastian.huber@embedded-brains.de" To: gcc-bugs@gcc.gnu.org Subject: [Bug gcov-profile/108658] New: [GCOV] Function entry is not recorded in a function containing an infinite loop depending on the optimization level Date: Fri, 03 Feb 2023 15:12:26 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: gcov-profile X-Bugzilla-Version: 12.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: sebastian.huber@embedded-brains.de X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108658 Bug ID: 108658 Summary: [GCOV] Function entry is not recorded in a function containing an infinite loop depending on the optimization level Product: gcc Version: 12.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: gcov-profile Assignee: unassigned at gcc dot gnu.org Reporter: sebastian.huber@embedded-brains.de CC: marxin at gcc dot gnu.org Target Milestone: --- Consider the following test code: idle.c void *idle(void *ignored) { while (1) { /* Do nothing */ } return 0; } main.c #include void *idle(void *ignored); int main(void) { pthread_t th; pthread_create(&th, NULL, idle, NULL); sleep(1); return 0; } This sequence of commands shows that the idle() function entry is not recor= ded for -O2 and -Og: gcc-12 -O2 --coverage -c main.c rm -f *.gc?? gcc-12 -O2 --coverage -c idle.c gcc-12 -pthread --coverage main.o idle.o ./a.out gcov-12 idle.c File 'idle.c' Lines executed:0.00% of 1 Creating 'idle.c.gcov' Lines executed:0.00% of 1 cat idle.c.gcov -: 0:Source:idle.c -: 0:Graph:idle.gcno -: 0:Data:idle.gcda -: 0:Runs:1 #####: 1:void *idle(void *ignored) -: 2:{ -: 3: while (1) { -: 4: /* Do nothing */ -: 5: } -: 6: -: 7: return 0; -: 8:} rm -f *.gc?? gcc-12 -Og --coverage -c idle.c gcc-12 -pthread --coverage main.o idle.o ./a.out gcov-12 idle.c File 'idle.c' Lines executed:50.00% of 2 Creating 'idle.c.gcov' Lines executed:50.00% of 2 cat idle.c.gcov -: 0:Source:idle.c -: 0:Graph:idle.gcno -: 0:Data:idle.gcda -: 0:Runs:1 #####: 1:void *idle(void *ignored) -: 2:{ 472195650: 3: while (1) { -: 4: /* Do nothing */ -: 5: } -: 6: -: 7: return 0; -: 8:} rm -f *.gc?? gcc-12 -O0 --coverage -c idle.c gcc-12 -pthread --coverage main.o idle.o ./a.out gcov-12 idle.c File 'idle.c' Lines executed:100.00% of 2 Creating 'idle.c.gcov' Lines executed:100.00% of 2 cat idle.c.gcov -: 0:Source:idle.c -: 0:Graph:idle.gcno -: 0:Data:idle.gcda -: 0:Runs:1 472440920: 1:void *idle(void *ignored) -: 2:{ 472440920: 3: while (1) { -: 4: /* Do nothing */ -: 5: } -: 6: -: 7: return 0; -: 8:} For -O0 the line count is also wrong from my point of view. Line 1 should h= ave a count of 1.=