Skip to content

Commit 3fc11f3

Browse files
committed
Instrument.C: only pass builtin macros when needed
We should avoid passing builtin macros to the actual preprocessor: we will just end up redefining all of the macros, and this will result in warnings at coverage time, as we are preprocessing again the code for some report formats (such as xml). Change-Id: I3c6da05e0efd84b31d1fbd55261dd1dc064897a6 TN: V914-024
1 parent d2a6d4a commit 3fc11f3

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

tools/gnatcov/instrument-c.adb

+7-4
Original file line numberDiff line numberDiff line change
@@ -2420,7 +2420,7 @@ package body Instrument.C is
24202420
-- Add the preprocessing flag
24212421

24222422
Append_Arg (Cmd, "-E");
2423-
Add_Options (Cmd.Arguments, Options);
2423+
Add_Options (Cmd.Arguments, Options, Pass_Builtins => False);
24242424

24252425
Append_Arg (Cmd, Filename);
24262426

@@ -3822,8 +3822,9 @@ package body Instrument.C is
38223822
-----------------
38233823

38243824
procedure Add_Options
3825-
(Args : in out String_Vectors.Vector; Options : Analysis_Options)
3826-
is
3825+
(Args : in out String_Vectors.Vector;
3826+
Options : Analysis_Options;
3827+
Pass_Builtins : Boolean := True) is
38273828

38283829
procedure Add_Macro_Switches (Macros : Macro_Vectors.Vector);
38293830
-- Add the given macro switches to Args
@@ -3856,7 +3857,9 @@ package body Instrument.C is
38563857
-- latter should have precedence over builtins and thus must come last
38573858
-- in Args.
38583859

3859-
Add_Macro_Switches (Options.Builtin_Macros);
3860+
if Pass_Builtins then
3861+
Add_Macro_Switches (Options.Builtin_Macros);
3862+
end if;
38603863
Add_Macro_Switches (Options.PP_Macros);
38613864

38623865
-- The -std switch also indicates the C/C++ version used, and

tools/gnatcov/instrument-c.ads

+5-2
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,11 @@ package Instrument.C is
250250
-- Options to analyze (preprocess and/or parse) a compilation unit
251251

252252
procedure Add_Options
253-
(Args : in out String_Vectors.Vector; Options : Analysis_Options);
254-
-- Append to Args the command line options corresponding to Options
253+
(Args : in out String_Vectors.Vector;
254+
Options : Analysis_Options;
255+
Pass_Builtins : Boolean := True);
256+
-- Append to Args the command line options corresponding to Options. If
257+
-- Pass_Builtins is True, pass builtin macros in Options to Args.
255258

256259
procedure Import_From_Project
257260
(Self : out Analysis_Options;

0 commit comments

Comments
 (0)