Skip to content

Commit bb7c7eb

Browse files
authored
[GCChecker] report FunctionDecl and type for missing JL_NOTSAFEPOINT calls (#46834)
In C++, some calls are implicit, which makes the call alone ambiguous and the message unclear. This helps clarify it.
1 parent 91d8e38 commit bb7c7eb

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

Make.inc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,6 @@ CLANGSA_FLAGS :=
13731373
CLANGSA_CXXFLAGS :=
13741374
ifeq ($(OS), Darwin) # on new XCode, the files are hidden
13751375
CLANGSA_FLAGS += -isysroot $(shell xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
1376-
CLANGSA_CXXFLAGS += -isystem $(shell xcode-select -p)/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
13771376
endif
13781377
ifeq ($(USEGCC),1)
13791378
# try to help clang find the c++ files for CC by guessing the value for --prefix

src/clangsa/GCChecker.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ class GCChecker
5353
check::Location> {
5454
mutable std::unique_ptr<BugType> BT;
5555
template <typename callback>
56-
void report_error(callback f, CheckerContext &C, const char *message) const;
57-
void report_error(CheckerContext &C, const char *message) const {
56+
void report_error(callback f, CheckerContext &C, StringRef message) const;
57+
void report_error(CheckerContext &C, StringRef message) const {
5858
return report_error([](PathSensitiveBugReport *) {}, C, message);
5959
}
6060
void
@@ -509,7 +509,7 @@ PDP GCChecker::GCValueBugVisitor::VisitNode(const ExplodedNode *N,
509509

510510
template <typename callback>
511511
void GCChecker::report_error(callback f, CheckerContext &C,
512-
const char *message) const {
512+
StringRef message) const {
513513
// Generate an error node.
514514
ExplodedNode *N = C.generateErrorNode();
515515
if (!N)
@@ -1230,8 +1230,15 @@ void GCChecker::checkPreCall(const CallEvent &Call, CheckerContext &C) const {
12301230
// We could separate out "not safepoint, except for noreturn functions",
12311231
// but that seems like a lot of effort with little benefit.
12321232
if (!FD || !FD->isNoReturn()) {
1233-
report_error(C, "Calling potential safepoint from function annotated "
1234-
"JL_NOTSAFEPOINT");
1233+
report_error(
1234+
[&](PathSensitiveBugReport *Report) {
1235+
if (FD)
1236+
Report->addNote(
1237+
"Tried to call method defined here",
1238+
PathDiagnosticLocation::create(FD, C.getSourceManager()));
1239+
},
1240+
C, ("Calling potential safepoint as " +
1241+
Call.getKindAsString() + " from function annotated JL_NOTSAFEPOINT").str());
12351242
return;
12361243
}
12371244
}

test/clangsa/GCPushPop.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// RUN: clang -D__clang_gcanalyzer__ --analyze -Xanalyzer -analyzer-output=text -Xclang -load -Xclang libGCCheckerPlugin%shlibext -Xclang -verify -I%julia_home/src -I%julia_home/src/support -I%julia_home/usr/include ${CLANGSA_FLAGS} ${CPPFLAGS} ${CFLAGS} -Xclang -analyzer-checker=core,julia.GCChecker --analyzer-no-default-checks -x c++ %s
44

55
#include "julia.h"
6+
#include <string>
67

78
void missingPop() {
89
jl_value_t *x = NULL;
@@ -34,3 +35,22 @@ void jl_gc_run_finalizers_in_list(jl_ptls_t ptls, arraylist_t *list)
3435
// run_finalizer(ptls, items[i], items[i + 1]);
3536
JL_GC_POP();
3637
}
38+
39+
void safepoint(void);
40+
bool testfunc1() JL_NOTSAFEPOINT
41+
{
42+
struct implied_struct1 { // expected-note{{Tried to call method defined here}}
43+
std::string s;
44+
struct implied_constructor { } x;
45+
} x; // expected-warning{{Calling potential safepoint as CXXConstructorCall from function annotated JL_NOTSAFEPOINT}}
46+
// expected-note@-1{{Calling potential safepoint as CXXConstructorCall from function annotated JL_NOTSAFEPOINT}}
47+
return 1;
48+
}
49+
bool testfunc2() JL_NOTSAFEPOINT
50+
{
51+
struct implied_struct2 { // expected-note{{Tried to call method defined here}}
52+
std::string s;
53+
} x{""};
54+
return 1; // expected-warning{{Calling potential safepoint as CXXDestructorCall from function annotated JL_NOTSAFEPOINT}}
55+
// expected-note@-1{{Calling potential safepoint as CXXDestructorCall from function annotated JL_NOTSAFEPOINT}}
56+
}

0 commit comments

Comments
 (0)