Skip to content

Commit c233f9a

Browse files
committed
C++ instr: do not instrument constexpr
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).
1 parent ed88172 commit c233f9a

File tree

6 files changed

+215
-64
lines changed

6 files changed

+215
-64
lines changed
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)