Skip to content

Commit 3707b05

Browse files
committed
[analyzer] DeadStores: Add a crude suppression files generated by DriverKit IIG.
IIG is a replacement for MIG in DriverKit: IIG is autogenerating C++ code. Suppress dead store warnings on such code, as the tool seems to be producing them regularly, and the users of IIG are not in position to address these warnings, as they don't control the autogenerated code. IIG-generated code is identified by looking at the comments at the top of the file. Differential Revision: https://reviews.llvm.org/D63118 llvm-svn: 363892
1 parent b03854f commit 3707b05

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,26 @@ class DeadStoreObs : public LiveVariables::Observer {
160160
return InEH->count(D);
161161
}
162162

163+
bool isSuppressed(SourceRange R) {
164+
SourceManager &SMgr = Ctx.getSourceManager();
165+
SourceLocation Loc = R.getBegin();
166+
if (!Loc.isValid())
167+
return false;
168+
169+
FileID FID = SMgr.getFileID(Loc);
170+
bool Invalid = false;
171+
StringRef Data = SMgr.getBufferData(FID, &Invalid);
172+
if (Invalid)
173+
return false;
174+
175+
// Files autogenerated by DriverKit IIG contain some dead stores that
176+
// we don't want to report.
177+
if (Data.startswith("/* iig generated from"))
178+
return true;
179+
180+
return false;
181+
}
182+
163183
void Report(const VarDecl *V, DeadStoreKind dsk,
164184
PathDiagnosticLocation L, SourceRange R) {
165185
if (Escaped.count(V))
@@ -175,6 +195,9 @@ class DeadStoreObs : public LiveVariables::Observer {
175195
if (!reachableCode->isReachable(currentBlock))
176196
return;
177197

198+
if (isSuppressed(R))
199+
return;
200+
178201
SmallString<64> buf;
179202
llvm::raw_svector_ostream os(buf);
180203
const char *BugType = nullptr;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* iig generated from SomethingSomething.iig */
2+
3+
// The comment above is the whole point of the test.
4+
// That's how the suppression works.
5+
// It needs to be on the top.
6+
// Run-lines can wait.
7+
8+
// RUN: %clang_analyze_cc1 -w -triple x86_64-apple-driverkit19.0 \
9+
// RUN: -analyzer-checker=deadcode -verify %s
10+
11+
// expected-no-diagnostics
12+
13+
#include "os_object_base.h"
14+
15+
class OSSomething {
16+
kern_return_t Invoke(const IORPC);
17+
void foo(OSDispatchMethod supermethod) {
18+
kern_return_t ret;
19+
IORPC rpc;
20+
// Test the DriverKit specific suppression in the dead stores checker.
21+
if (supermethod) ret = supermethod((OSObject *)this, rpc); // no-warning
22+
else ret = ((OSObject *)this)->Invoke(rpc); // no-warning
23+
}
24+
};

clang/test/Analysis/os_object_base.h

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
using size_t = decltype(sizeof(int));
2121

22+
typedef int kern_return_t;
23+
struct IORPC {};
24+
2225
struct OSMetaClass;
2326

2427
struct OSMetaClassBase {
@@ -37,8 +40,13 @@ struct OSMetaClassBase {
3740

3841
virtual void free();
3942
virtual ~OSMetaClassBase(){};
43+
44+
kern_return_t Invoke(IORPC invoke);
4045
};
4146

47+
typedef kern_return_t (*OSDispatchMethod)(OSMetaClassBase *self,
48+
const IORPC rpc);
49+
4250
struct OSObject : public OSMetaClassBase {
4351
virtual ~OSObject(){}
4452

0 commit comments

Comments
 (0)