Skip to content

Commit e42a69d

Browse files
committed
Generate an empty buffers unit list that is -pedantic compliant
1 parent 08c743b commit e42a69d

File tree

5 files changed

+84
-9
lines changed

5 files changed

+84
-9
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CC=g++
2+
OBJ = pkg.o test.o
3+
4+
%.o: %.c
5+
$(CC) -c -pedantic -Wall -o $@ $<
6+
7+
test: $(OBJ)
8+
$(CC) -pedantic -o $@ $^
9+
10+
clean:
11+
rm -f *.o test
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
int
2+
foo ()
3+
{
4+
return 0;
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
extern int foo ();
2+
3+
int
4+
main ()
5+
{
6+
foo ();
7+
return 0;
8+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
Check that gnatcov does not break compilation with the -pedantic switch. The
3+
code generated for an empty buffers list used to be uncompilable with
4+
-pedantic. Note that -pedantic should only diagnose warnings and not errors,
5+
so this is not expected, but we can work around the issue easily so fix the
6+
wrong code.
7+
"""
8+
9+
import os
10+
import os.path
11+
12+
from e3.fs import cp
13+
14+
from SUITE.control import env
15+
from SUITE.cutils import Wdir
16+
from SCOV.minicheck import check_xcov_reports
17+
from SUITE.tutils import cmdrun, srctracename_for, thistest, xcov
18+
19+
Wdir("tmp_")
20+
21+
cwd = os.getcwd()
22+
23+
# Then, setup the instrumentation process
24+
xcov(
25+
[
26+
"setup-integration",
27+
"--level=stmt",
28+
"--compilers=g++",
29+
f"--output-dir={cwd}",
30+
]
31+
)
32+
33+
# Shadow the compiler driver with the generated wrapper
34+
env.add_search_path(env_var="PATH", path=cwd)
35+
36+
# Then, run the build process unchanged
37+
cmdrun(["make", "-C", "..", "test"], for_pgm=False)
38+
39+
# Run the executable
40+
cmdrun(["../test"], for_pgm=False)
41+
42+
thistest.result()

tools/gnatcov/instrument-c.adb

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4413,15 +4413,24 @@ package body Instrument.C is
44134413
CU_File.Put_Line (Self.Extern_Prefix & Buffer_Array_Decl & ";");
44144414
CU_File.Put_Line (Buffer_Array_Decl & " = {");
44154415
CU_File.Put_Line (" " & Buffer_Unit_Length & ",");
4416-
CU_File.Put_Line
4417-
(" (const struct gnatcov_rts_coverage_buffers_group *[]) {");
4418-
for BS of Buffer_Symbols loop
4419-
CU_File.Put (" &" & (+BS));
4420-
if BS /= Buffer_Symbols.Last_Element then
4421-
CU_File.Put_Line (",");
4422-
end if;
4423-
end loop;
4424-
CU_File.Put_Line ("}};");
4416+
if String_Sets.Length (Buffer_Symbols) = 0 then
4417+
4418+
-- If there are no units of interest, create a NULL pointer to avoid
4419+
-- having an empty array.
4420+
4421+
CU_File.Put_Line ("NULL");
4422+
else
4423+
CU_File.Put_Line
4424+
(" (const struct gnatcov_rts_coverage_buffers_group *[]) {");
4425+
for BS of Buffer_Symbols loop
4426+
CU_File.Put (" &" & (+BS));
4427+
if BS /= Buffer_Symbols.Last_Element then
4428+
CU_File.Put_Line (",");
4429+
end if;
4430+
end loop;
4431+
CU_File.Put_Line ("}");
4432+
end if;
4433+
CU_File.Put_Line ("};");
44254434
return CU_Name;
44264435
end Emit_Buffers_List_Unit;
44274436

0 commit comments

Comments
 (0)