Skip to content

Commit e59b90d

Browse files
committed
[CHERI-CSA] clang-format
1 parent 11ff3c0 commit e59b90d

File tree

13 files changed

+520
-652
lines changed

13 files changed

+520
-652
lines changed

clang/include/clang/StaticAnalyzer/Checkers/Checkers.td

Lines changed: 51 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,8 +1675,8 @@ def UnixAPIPortabilityChecker : Checker<"UnixAPI">,
16751675
Documentation<NotDocumented>;
16761676

16771677
def PointerAlignmentChecker : Checker<"PointerAlignment">,
1678-
HelpText<"Check underaligned pointers.">,
1679-
Documentation<NotDocumented>;
1678+
HelpText<"Check underaligned pointers.">,
1679+
Documentation<NotDocumented>;
16801680

16811681
} // end optin.portability
16821682

@@ -1794,62 +1794,59 @@ def UncheckedLocalVarsChecker : Checker<"UncheckedLocalVarsChecker">,
17941794

17951795
let ParentPackage = CHERI in {
17961796

1797-
def CheriAPIModelling : Checker<"CheriAPIModelling">,
1798-
HelpText<"Model CheriAPI">,
1799-
Documentation<NotDocumented>;
1800-
1801-
def ProvenanceSourceChecker : Checker<"ProvenanceSource">,
1802-
HelpText<"Check expressions with ambiguous provenance source.">,
1803-
CheckerOptions<[
1804-
CmdLineOption<Boolean,
1805-
"ShowFixIts",
1806-
"Enable fix-it hints for this checker",
1807-
"false",
1808-
InAlpha>,
1809-
CmdLineOption<Boolean,
1810-
"ReportForAmbiguousProvenance",
1811-
"Report for binary operations with ambiguous provenance "
1812-
"for which the default capability derivation from LHS is fine. "
1813-
"Disabled if [-Wcheri-provenance] is disabled.",
1814-
"true",
1815-
Released>
1816-
]>,
1817-
Documentation<NotDocumented>;
1818-
1819-
def CapabilityCopyChecker : Checker<"CapabilityCopy">,
1820-
HelpText<"Check tag-stripping memory copy.">,
1821-
CheckerOptions<[
1822-
CmdLineOption<Boolean,
1823-
"ReportForCharPtr",
1824-
"Report tag-stripping copy for char* function parameters. "
1825-
"Suppression of warnings for C-strings is used to reduce "
1826-
"the number of false alarms, but it's not very reliable.",
1827-
"false",
1828-
Released>
1829-
]>,
1830-
Documentation<NotDocumented>;
1831-
1832-
def PointerSizeAssumptionsChecker : Checker<"PointerSizeAssumptions">,
1833-
HelpText<"Detect hardcoded expectations on pointer sizes">,
1834-
Documentation<NotDocumented>;
1835-
1836-
def SubObjectRepresentabilityChecker : Checker<"SubObjectRepresentability">,
1837-
HelpText<"Check for record fields with unrepresentable subobject bounds">,
1838-
Documentation<NotDocumented>;
1797+
def CheriAPIModelling : Checker<"CheriAPIModelling">,
1798+
HelpText<"Model CheriAPI">,
1799+
Documentation<NotDocumented>;
1800+
1801+
def ProvenanceSourceChecker
1802+
: Checker<"ProvenanceSource">,
1803+
HelpText<"Check expressions with ambiguous provenance source.">,
1804+
CheckerOptions<
1805+
[CmdLineOption<Boolean, "ShowFixIts",
1806+
"Enable fix-it hints for this checker", "false",
1807+
InAlpha>,
1808+
CmdLineOption<
1809+
Boolean, "ReportForAmbiguousProvenance",
1810+
"Report for binary operations with ambiguous provenance "
1811+
"for which the default capability derivation from LHS is "
1812+
"fine. "
1813+
"Disabled if [-Wcheri-provenance] is disabled.",
1814+
"true", Released>]>,
1815+
Documentation<NotDocumented>;
1816+
1817+
def CapabilityCopyChecker
1818+
: Checker<"CapabilityCopy">,
1819+
HelpText<"Check tag-stripping memory copy.">,
1820+
CheckerOptions<[CmdLineOption<
1821+
Boolean, "ReportForCharPtr",
1822+
"Report tag-stripping copy for char* function parameters. "
1823+
"Suppression of warnings for C-strings is used to reduce "
1824+
"the number of false alarms, but it's not very reliable.",
1825+
"false", Released>]>,
1826+
Documentation<NotDocumented>;
1827+
1828+
def PointerSizeAssumptionsChecker
1829+
: Checker<"PointerSizeAssumptions">,
1830+
HelpText<"Detect hardcoded expectations on pointer sizes">,
1831+
Documentation<NotDocumented>;
1832+
1833+
def SubObjectRepresentabilityChecker
1834+
: Checker<"SubObjectRepresentability">,
1835+
HelpText<
1836+
"Check for record fields with unrepresentable subobject bounds">,
1837+
Documentation<NotDocumented>;
18391838

18401839
} // end cheri
18411840

18421841
let ParentPackage = CHERIAlpha in {
18431842

1844-
def AllocationChecker : Checker<"Allocation">,
1845-
HelpText<"Suggest narrowing bounds for escaping suballocation capabilities">,
1846-
CheckerOptions<[
1847-
CmdLineOption<Boolean,
1848-
"ReportForUnknownAllocations",
1849-
"Report for pointers with untracked origin",
1850-
"true",
1851-
Released>
1852-
]>,
1853-
Documentation<NotDocumented>;
1843+
def AllocationChecker
1844+
: Checker<"Allocation">,
1845+
HelpText<
1846+
"Suggest narrowing bounds for escaping suballocation capabilities">,
1847+
CheckerOptions<[CmdLineOption<
1848+
Boolean, "ReportForUnknownAllocations",
1849+
"Report for pointers with untracked origin", "true", Released>]>,
1850+
Documentation<NotDocumented>;
18541851

18551852
} // end alpha.cheri

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "clang/Basic/CLWarnings.h"
2929
#include "clang/Basic/CharInfo.h"
3030
#include "clang/Basic/CodeGenOptions.h"
31-
#include <clang/Basic/DiagnosticSema.h>
3231
#include "clang/Basic/HeaderInclude.h"
3332
#include "clang/Basic/LangOptions.h"
3433
#include "clang/Basic/MakeSupport.h"
@@ -67,6 +66,7 @@
6766
#include "llvm/TargetParser/RISCVISAInfo.h"
6867
#include "llvm/TargetParser/RISCVTargetParser.h"
6968
#include <cctype>
69+
#include <clang/Basic/DiagnosticSema.h>
7070

7171
using namespace clang::driver;
7272
using namespace clang::driver::tools;

clang/lib/StaticAnalyzer/Checkers/CHERI/AllocationChecker.cpp

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,50 +18,40 @@
1818
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
1919
#include "clang/StaticAnalyzer/Core/Checker.h"
2020
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
21-
#include <clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h>
2221
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
2322
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
2423
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
25-
24+
#include <clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h>
2625

2726
using namespace clang;
2827
using namespace ento;
2928
using namespace cheri;
3029

31-
3230
struct EscapeInfo {
3331
PointerEscapeKind Kind;
3432
EscapeInfo(PointerEscapeKind K) : Kind(K) {};
35-
bool operator==(const EscapeInfo &X) const {
36-
return Kind == X.Kind;
37-
}
38-
void Profile(llvm::FoldingSetNodeID &ID) const {
39-
ID.AddInteger(Kind);
40-
}
33+
bool operator==(const EscapeInfo &X) const { return Kind == X.Kind; }
34+
void Profile(llvm::FoldingSetNodeID &ID) const { ID.AddInteger(Kind); }
4135
};
42-
using EscapePair = std::pair<const MemRegion*, EscapeInfo>;
36+
using EscapePair = std::pair<const MemRegion *, EscapeInfo>;
4337

4438
namespace {
45-
class AllocationChecker : public Checker<check::PostStmt<CastExpr>,
46-
check::PreCall,
47-
check::PostCall,
48-
check::Bind,
49-
check::EndFunction,
50-
check::DeadSymbols> {
39+
class AllocationChecker
40+
: public Checker<check::PostStmt<CastExpr>, check::PreCall, check::PostCall,
41+
check::Bind, check::EndFunction, check::DeadSymbols> {
5142
BugType BT_Default{this, "Allocation partitioning", "CHERI portability"};
5243
BugType BT_UnknownReg{this, "Unknown allocation partitioning",
53-
"CHERI portability"};
44+
"CHERI portability"};
5445

5546
const CallDescriptionSet IgnoreFnSet = {
5647
{CDM::SimpleFunc, {"free"}, 1},
5748
};
5849

5950
const CallDescriptionSet CheriBoundsFnSet = {
60-
{CDM::SimpleFunc, {"cheri_bounds_set"}, 2},
61-
{CDM::SimpleFunc, {"cheri_bounds_set_exact"}, 2},
51+
{CDM::SimpleFunc, {"cheri_bounds_set"}, 2},
52+
{CDM::SimpleFunc, {"cheri_bounds_set_exact"}, 2},
6253
};
6354

64-
6555
class AllocPartitionBugVisitor : public BugReporterVisitor {
6656
public:
6757
AllocPartitionBugVisitor(const MemRegion *P, const MemRegion *A)
@@ -72,7 +62,6 @@ class AllocationChecker : public Checker<check::PostStmt<CastExpr>,
7262
ID.AddPointer(&X);
7363
ID.AddPointer(PrevAlloc);
7464
ID.AddPointer(SubAlloc);
75-
7665
}
7766

7867
PathDiagnosticPieceRef VisitNode(const ExplodedNode *N,
@@ -109,7 +98,6 @@ REGISTER_MAP_WITH_PROGRAMSTATE(ShiftMap, const MemRegion *, const MemRegion *)
10998
REGISTER_SET_WITH_PROGRAMSTATE(SuballocationSet, const MemRegion *)
11099
REGISTER_SET_WITH_PROGRAMSTATE(BoundedSet, const MemRegion *)
111100

112-
113101
namespace {
114102
std::pair<const MemRegion *, bool> getAllocationStart(const ASTContext &ASTCtx,
115103
const MemRegion *R,
@@ -126,7 +114,7 @@ std::pair<const MemRegion *, bool> getAllocationStart(const ASTContext &ASTCtx,
126114
return std::make_pair(R, ZeroShift);
127115
}
128116

129-
bool isAllocation(const MemRegion *R, const AllocationChecker* Chk) {
117+
bool isAllocation(const MemRegion *R, const AllocationChecker *Chk) {
130118
if (!Chk->ReportForUnknownAllocations) {
131119
const MemSpaceRegion *MemSpace = R->getMemorySpace();
132120
if (!isa<HeapSpaceRegion, GlobalsSpaceRegion, StackSpaceRegion>(MemSpace))
@@ -308,28 +296,35 @@ void AllocationChecker::checkPreCall(const CallEvent &Call,
308296

309297
ProgramStateRef State = C.getState();
310298
ExplodedNode *N = nullptr;
311-
bool Updated = false;
299+
bool Updated = false;
312300
for (unsigned Arg = 0; Arg < Call.getNumArgs(); ++Arg) {
313301
const Expr *ArgExpr = Call.getArgExpr(Arg);
314302
if (const MemRegion *MR = C.getSVal(ArgExpr).getAsRegion()) {
315303
if (State->contains<SuballocationSet>(MR)) {
316304
SmallString<256> Buf;
317305
llvm::raw_svector_ostream OS(Buf);
318-
OS << "Pointer to suballocation passed to function as " << (Arg+1);
306+
OS << "Pointer to suballocation passed to function as " << (Arg + 1);
319307
if (Arg + 1 < 11) {
320-
switch (Arg+1) {
321-
case 1: OS << "st"; break;
322-
case 2: OS << "nd"; break;
323-
case 3: OS << "rd"; break;
324-
default: OS << "th"; break;
308+
switch (Arg + 1) {
309+
case 1:
310+
OS << "st";
311+
break;
312+
case 2:
313+
OS << "nd";
314+
break;
315+
case 3:
316+
OS << "rd";
317+
break;
318+
default:
319+
OS << "th";
320+
break;
325321
}
326322
}
327323

328324
OS << " argument";
329325
OS << " (consider narrowing the bounds for suballocation)";
330-
N = emitAllocationPartitionWarning(
331-
C, MR, ArgExpr->getSourceRange(),
332-
OS.str());
326+
N = emitAllocationPartitionWarning(C, MR, ArgExpr->getSourceRange(),
327+
OS.str());
333328
if (N) {
334329
State = State->remove<SuballocationSet>(MR);
335330
Updated = true;

clang/lib/StaticAnalyzer/Checkers/CHERI/CHERIUtils.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
1313

14-
1514
namespace clang {
1615
namespace ento {
1716
namespace cheri {

clang/lib/StaticAnalyzer/Checkers/CHERI/CHERIUtils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_CHERI_CHERIUTILS_H
1111

1212
#include "clang/StaticAnalyzer/Core/Checker.h"
13-
#include <clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h>
1413
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
14+
#include <clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h>
1515

1616
namespace clang {
1717
namespace ento {
@@ -59,7 +59,7 @@ inline bool isLive(SymbolReaper &SymReaper, SymbolRef Sym) {
5959

6060
template <typename M>
6161
ProgramStateRef cleanDead(ProgramStateRef State, SymbolReaper &SymReaper,
62-
bool &Removed) {
62+
bool &Removed) {
6363
const typename ProgramStateTrait<M>::data_type &Map = State->get<M>();
6464
for (const auto &E : Map) {
6565
const typename ProgramStateTrait<M>::key_type &K = getKey<M>(E);

0 commit comments

Comments
 (0)