Skip to content

Commit 6763b57

Browse files
committed
Merge branch 'eyraud/c++_constexpr' into 'master'
C++ instr: do not instrument constexpr See merge request eng/cov/gnatcoverage!233 Instrumenting constexpr functions violates the constexpr semantics and there is no straightforward valid way of instrumenting such code constructs. Skip their instrumentation altogether for the moment, as their use is quite limited (they are only allowed to return literal values). Ref: eng/cov/gnatcoverage#101
2 parents df7984d + b7b713d commit 6763b57

18 files changed

+672
-472
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ repos:
1313
IndentExternBlock: NoIndent,
1414

1515
SpaceAfterCStyleCast: true,
16-
UseTab: ForContinuationAndIndentation,
1716
SpacesInLineCommentPrefix: {
1817
Minimum: 0,
1918
Maximum: -1

testsuite/SCOV/internals/driver.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,8 @@ def mode_build(self):
13011301
dump_trigger=self.dump_trigger,
13021302
gprsw=instrument_gprsw,
13031303
gpr_obj_dir=self.gpr_obj_dir,
1304-
out=out)
1304+
out=out,
1305+
tolerate_messages=self.testcase.tolerate_messages)
13051306

13061307
# When exception propagation is not available, a test ending with an
13071308
# unhandled exception goes straight to the last_chance_handler from
@@ -1328,11 +1329,12 @@ def mode_build(self):
13281329
# Standard output might contain warnings indicating instrumentation
13291330
# issues. This should not happen, so simply fail as soon as the output
13301331
# file is not empty.
1331-
thistest.fail_if(
1332-
os.path.getsize(out) > 0,
1333-
'xcov instrument standard output not empty ({}):'
1334-
'\n--'
1335-
'\n{}'.format(out, contents_of(out)))
1332+
if not self.testcase.tolerate_messages:
1333+
thistest.fail_if(
1334+
os.path.getsize(out) > 0,
1335+
'xcov instrument standard output not empty ({}):'
1336+
'\n--'
1337+
'\n{}'.format(out, contents_of(out)))
13361338

13371339
# Now we can build, instructing gprbuild to fetch the instrumented
13381340
# sources in their dedicated subdir:

testsuite/SCOV/tc.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,16 @@ def __drivers_from(self, cspec):
123123
# match this expression
124124
return [drv for drv in self.all_drivers if re.search(drv_expr, drv)]
125125

126-
def __init__(self, extradrivers="", extracargs="", category=CAT.auto):
126+
def __init__(self, extradrivers="", extracargs="", category=CAT.auto,
127+
tolerate_messages=None):
127128
# By default, these test cases expect no error from subprocesses (xrun,
128129
# xcov, etc.)
129130
self.expect_failures = False
130131

132+
# Pass tolerate_messages to gnatcov instrument invocations (see the doc
133+
# for xcov_instrument).
134+
self.tolerate_messages = tolerate_messages
135+
131136
# Step 1: Compute the list of drivers and consolidation specs
132137
# to exercise
133138
# ------------------------------------------------------------
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
constexpr int
2+
foo ()
3+
{
4+
if (true && false) // # ce-body
5+
return 1; // # ce-body
6+
constexpr bool a = true; // # ce-body
7+
if constexpr (false) // # ce-body
8+
return 1; // # ce-body
9+
return 0; // # ce-body
10+
}
11+
12+
int
13+
main(){
14+
constexpr bool a = true || false; // # single-ce-decl
15+
constexpr bool b = true || false, c = true || false; // # double-ce-decl
16+
if constexpr (false) // # if-ce
17+
return 1; // # if-rt
18+
return 0; // # rt
19+
}
20+
21+
//# test_constexpr.cpp
22+
//
23+
// /ce-body/ l? ## s?
24+
// /single-ce-decl/ l? ## d?
25+
// /double-ce-decl/ l? ## d?, d?
26+
// /if-ce/ l? ## d?
27+
// /if-rt/ l- ## s-
28+
// /rt/ l+ ## 0
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from SCOV.tc import TestCase
2+
from SUITE.context import thistest
3+
4+
TestCase(tolerate_messages=r".* cannot instrument constexpr").run()
5+
thistest.result()

tools/gnatcov/clang-extensions.adb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@ package body Clang.Extensions is
9090
return Opcode_Str;
9191
end Get_Opcode_Str;
9292

93+
------------------
94+
-- Is_Constexpr --
95+
------------------
96+
97+
function Is_Constexpr (C : Cursor_T) return Boolean
98+
is
99+
function Is_Constexpr_C (C : Cursor_T) return unsigned
100+
with
101+
Import, Convention => C,
102+
External_Name => "clang_isConstexpr";
103+
begin
104+
return Is_Constexpr_C (C) /= 0;
105+
end Is_Constexpr;
106+
93107
-----------------------------------
94108
-- CX_Rewriter_Insert_Text_After --
95109
-----------------------------------

tools/gnatcov/clang-extensions.ads

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ package Clang.Extensions is
8888

8989
function Get_Callee_Name_Str (C : Cursor_T) return String with Inline;
9090

91+
function Is_Constexpr (C : Cursor_T) return Boolean with Inline;
92+
9193
function Unwrap (C : Cursor_T) return Cursor_T
9294
with Import, Convention => C, External_Name => "clang_unwrap";
9395

0 commit comments

Comments
 (0)