https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121082
Bug ID: 121082
Summary: [GCOV] Anonymous structure initialization combined
with return statement leads to incorrect coverage
count
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: gcov-profile
Assignee: unassigned at gcc dot gnu.org
Reporter: njuwy at smail dot nju.edu.cn
Target Milestone: ---
gcc version:
gcc version 16.0.0 20250704 (experimental) (GCC)
option:
--coverage -std=c2x
$ cat test.c
typedef struct {
float x;
float y;
} Point;
Point transform(Point a, Point b) {
return (Point){.x = a.x * 2 + b.x / 3,
.y = b.y * 3 - a.y / 2,
};
}
int main() {
Point p1 = {1.5f, 2.0f};
Point p2 = {4.0f, 6.0f};
Point result1 = transform(p1, p2);
Point result2 = (Point){.x = p1.x * 2 + p2.x / 3,
.y = p2.y * 3 - p1.y / 2,
};
}
$ cat test.c.gcov
-: 1:typedef struct {
-: 2: float x;
-: 3: float y;
-: 4:} Point;
1: 5:Point transform(Point a, Point b) {
2: 6: return (Point){.x = a.x * 2 + b.x / 3,
1: 7: .y = b.y * 3 - a.y / 2,
-: 8: };
-: 9:}
1: 10:int main() {
1: 11: Point p1 = {1.5f, 2.0f};
1: 12: Point p2 = {4.0f, 6.0f};
1: 13: Point result1 = transform(p1, p2);
1: 14: Point result2 = (Point){.x = p1.x * 2 + p2.x / 3,
1: 15: .y = p2.y * 3 - p1.y / 2,
-: 16: };
-: 17:}
coverage statistics of line 6 and 14 should be consistent as 1.