Skip to content

Commit b89dbe1

Browse files
3C code style pass 2021-02 (#462)
1 parent ff245c1 commit b89dbe1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+465
-456
lines changed

clang-tools-extra/clangd/3CCommands.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,17 @@ void as3CCommands(const Diagnostic &D, std::vector<Command> &OutCommands) {
4848
}
4949

5050
bool is3CCommand(const ExecuteCommandParams &Params) {
51-
return (Params.command.rfind(std::string(Command::_3C_APPLY_ONLY_FOR_THIS), 0) == 0) ||
52-
(Params.command.rfind(std::string(Command::_3C_APPLY_FOR_ALL), 0) == 0);
51+
return (Params.command.rfind(std::string(Command::_3C_APPLY_ONLY_FOR_THIS),
52+
0) == 0) ||
53+
(Params.command.rfind(std::string(Command::_3C_APPLY_FOR_ALL), 0) ==
54+
0);
5355
}
5456

5557
bool execute3CCommand(const ExecuteCommandParams &Params,
5658
std::string &ReplyMessage, _3CInterface &CcInterface) {
5759
ReplyMessage = "Checked C Pointer Modified.";
58-
if (Params.command.rfind(std::string(Command::_3C_APPLY_ONLY_FOR_THIS), 0) == 0) {
60+
if (Params.command.rfind(std::string(Command::_3C_APPLY_ONLY_FOR_THIS), 0) ==
61+
0) {
5962
int PtrId = Params.The3CManualFix->PtrId;
6063
CcInterface.makeSinglePtrNonWild(PtrId);
6164
return true;

clang-tools-extra/clangd/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,11 @@ endfunction()
156156
set(CLANGD_KNOWN_VARIANTS "clangd;clangd3c")
157157
set(CLANGD_EXCLUSIVE_VARIANT "" CACHE STRING
158158
"Variant of clangd to include in the configuration. If empty, include all variants.")
159-
set_property(CACHE CLANGD_EXCLUSIVE_VARIANT PROPERTY STRINGS ";${CLANGD_KNOWN_VARIANTS}")
159+
set_property(CACHE CLANGD_EXCLUSIVE_VARIANT
160+
PROPERTY STRINGS ";${CLANGD_KNOWN_VARIANTS}")
160161
foreach(variant ${CLANGD_KNOWN_VARIANTS})
161-
if(CLANGD_EXCLUSIVE_VARIANT STREQUAL "" OR CLANGD_EXCLUSIVE_VARIANT STREQUAL variant)
162+
if(CLANGD_EXCLUSIVE_VARIANT STREQUAL "" OR
163+
CLANGD_EXCLUSIVE_VARIANT STREQUAL variant)
162164
set(CLANGD_INCLUDE_VARIANT_${variant} ON)
163165
endif()
164166
endforeach()

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,8 @@ ClangdLSPServer::ClangdLSPServer(
14851485
llvm::Optional<OffsetEncoding> ForcedOffsetEncoding,
14861486
const ClangdServer::Options &Opts
14871487
#ifdef INTERACTIVE3C
1488-
, _3CInterface &Cinter
1488+
,
1489+
_3CInterface &Cinter
14891490
#endif
14901491
)
14911492
: BackgroundContext(Context::current().clone()), Transp(Transp),
@@ -1496,9 +1497,10 @@ ClangdLSPServer::ClangdLSPServer(
14961497
CompileCommandsDir(std::move(CompileCommandsDir)), ClangdServerOpts(Opts),
14971498
NegotiatedOffsetEncoding(ForcedOffsetEncoding)
14981499
#ifdef INTERACTIVE3C
1499-
, The3CInterface(Cinter)
1500+
,
1501+
The3CInterface(Cinter)
15001502
#endif
1501-
{
1503+
{
15021504
// clang-format off
15031505
#ifdef INTERACTIVE3C
15041506
// We only support these methods in Interactive 3C mode.

clang-tools-extra/clangd/ClangdLSPServer.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class SymbolIndex;
3939
/// The server also supports $/cancelRequest (MessageHandler provides this).
4040
class ClangdLSPServer : private ClangdServer::Callbacks
4141
#ifdef INTERACTIVE3C
42-
, public _3CLSPCallBack
42+
,
43+
public _3CLSPCallBack
4344
#endif
4445
{
4546
public:
@@ -55,9 +56,10 @@ class ClangdLSPServer : private ClangdServer::Callbacks
5556
llvm::Optional<OffsetEncoding> ForcedOffsetEncoding,
5657
const ClangdServer::Options &Opts
5758
#ifdef INTERACTIVE3C
58-
, _3CInterface &Cinter
59+
,
60+
_3CInterface &Cinter
5961
#endif
60-
);
62+
);
6163
/// The destructor blocks on any outstanding background tasks.
6264
~ClangdLSPServer();
6365

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
170170
std::make_unique<UpdateIndexCallbacks>(
171171
DynamicIdx.get(), Callbacks, Opts.TheiaSemanticHighlighting))
172172
#ifdef INTERACTIVE3C
173-
, _3CInter(_3CInterface)
173+
,
174+
_3CInter(_3CInterface)
174175
#endif
175-
{
176+
{
176177
// Adds an index to the stack, at higher priority than existing indexes.
177178
auto AddIndex = [&](SymbolIndex *Idx) {
178179
if (this->Index != nullptr) {

clang-tools-extra/clangd/Protocol.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,10 @@ bool fromJSON(const llvm::json::Value &, CodeActionParams &);
860860
#ifdef INTERACTIVE3C
861861
struct CodeLensParams {
862862
/// The document in which the command was invoked.
863+
// These fields seem to be intentionally named after the JSON fields in spite
864+
// of the LLVM naming guidelines. Does the rest of clangd just ignore the
865+
// readability-identifier-naming warnings?
866+
// NOLINTNEXTLINE(readability-identifier-naming)
863867
TextDocumentIdentifier textDocument;
864868
};
865869

clang-tools-extra/clangd/tool/ClangdMain.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,9 +977,10 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
977977
/*UseDirBasedCDB=*/CompileArgsFrom == FilesystemCompileArgs,
978978
OffsetEncodingFromFlag, Opts
979979
#ifdef INTERACTIVE3C
980-
, _3CInterface
980+
,
981+
_3CInterface
981982
#endif
982-
);
983+
);
983984
llvm::set_thread_name("clangd.main");
984985
int ExitCode = LSPServer.run()
985986
? 0

clang/docs/checkedc/3C/CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Contributing to 3C
22

33
Issues and pull requests related to 3C should be submitted to [CCI's
4-
`checkedc-clang` repository](https://github.com/correctcomputation/checkedc-clang), not
4+
`checkedc-clang`
5+
repository](https://github.com/correctcomputation/checkedc-clang), not
56
[Microsoft's](https://github.com/microsoft/checkedc-clang), except as
67
stated below.
78

clang/docs/checkedc/3C/README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,21 @@ Issues and pull requests related to 3C should be submitted to CCI's
4242
repository; see [CONTRIBUTING.md](CONTRIBUTING.md) for more
4343
information.
4444

45-
As of March 2021, 3C is pre-alpha quality and we are just starting
46-
to establish its public presence and processes. CCI is also working on
47-
a proprietary extension of 3C called 5C ("**C**orrect
48-
**C**omputation's **C**hecked-**C**-**C**onvert"). Our current plan is
49-
that 3C will contain the core inference logic, while 5C will add
50-
features to enhance developer productivity. If you'd like more
51-
information about 5C, please contact us at
52-
45+
As of March 2021, 3C is pre-alpha quality and we are just starting to
46+
establish its public presence and processes. CCI is also working on a
47+
proprietary extension of 3C called 5C ("**C**orrect **C**omputation's
48+
**C**hecked-**C**-**C**onvert"). Our current plan is that 3C will
49+
contain the core inference logic, while 5C will add features to
50+
enhance developer productivity. If you'd like more information about
51+
5C, please contact us at [email protected].
5352

5453
### Which `checkedc-clang` repository to use?
5554

5655
We typically recommend that serious 3C users use CCI's repository to
5756
get 3C fixes and enhancements sooner, but in some scenarios, you may
5857
be better off with Microsoft's repository. Here, in detail, are the
59-
factors we can think of that might affect your decision (as of
60-
March 2021):
58+
factors we can think of that might affect your decision (as of March
59+
2021):
6160

6261
- CCI strives to merge changes reasonably quickly from Microsoft's
6362
repository to CCI's, but most 3C-specific changes are made first in
@@ -94,10 +93,10 @@ March 2021):
9493
- On the other hand, some CCI engineers work on Mac OS X and
9594
frequently run the regression tests and other manual tests on CCI's
9695
copy of 3C on Mac OS X, while we are unaware of any testing of
97-
Microsoft's copy of 3C on Mac OS X. So you may be less
98-
likely to encounter Mac-specific problems with CCI's repository. But
99-
so far, when we've seen Mac-specific problems, we've usually gotten
100-
a fix into Microsoft's repository reasonably quickly.
96+
Microsoft's copy of 3C on Mac OS X. So you may be less likely to
97+
encounter Mac-specific problems with CCI's repository. But so far,
98+
when we've seen Mac-specific problems, we've usually gotten a fix
99+
into Microsoft's repository reasonably quickly.
101100

102101
As noted in the [setup instructions](INSTALL.md#basics), both 3C and
103102
the Checked C compiler depend on the Checked C system headers, which

clang/docs/checkedc/3C/clang-tidy.md

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,11 @@ yet decided what to do about; please try to avoid adding more though.
77

88
We're currently using version 11.0.0 due to bugs in older versions, so if you
99
want to verify that our code is compliant with `clang-tidy`, you'll need to get
10-
a copy of that version. If it isn't available from your OS distribution, you may
11-
need to build it from source. This repository is currently based on a
12-
pre-release of LLVM 9.0.0, so you can't use its version of `clang-tidy`.
13-
However, Microsoft plans to upgrade it to LLVM 11.0.0 soon, at which point
14-
you'll have the option to use `clang-tidy` built from this repository. It's
15-
possible that using a newer, unstable version of `clang-tidy` (e.g., LLVM
16-
master) might avoid more bugs, saving us the trouble of researching them, but we
17-
doubt it's worth relying on a version that is unstable _and_ newer than what
18-
Microsoft is about to upgrade to. This calculus might change when LLVM 12 is
19-
released, expected around March 2021.
10+
a copy of that version. Now that this repository is based on a pre-release of
11+
LLVM 11, `clang-tidy` built from it is probably OK. But you probably want a
12+
release build of `clang-tidy` rather than a debug build (a release build is
13+
significantly faster), so if your main build from this repository is debug, it
14+
might be easier to get `clang-tidy` another way.
2015

2116
This file maintains a list of issues we've run into that you should be aware of
2217
when using `clang-tidy`. Many of these could in principle be researched and (if
@@ -136,11 +131,29 @@ suppression.
136131
- Unwrapping an `else` branch may leave an unconditional return in an outer
137132
`if` branch that then makes it possible to unwrap the outer `else` branch.
138133

139-
- `readability-identifier-naming` may fail to update a reference to an element
140-
that it renamed. It turns out that the `--fix-errors` option not only makes
141-
`clang-tidy` proceed in the presence of compile errors but also makes it fix
142-
certain compile errors, including certain broken references, so a subsequent
143-
`clang-tidy --fix-errors` pass may be helpful.
134+
- We've seen many cases in which `readability-identifier-naming` fails to update
135+
some references to an element that it renamed. There may be several causes for
136+
this; we haven't found a comprehensive list on the web, so it's hard to know
137+
what the problem is in any given case.
138+
139+
The biggest cause seems to be elements that are defined in shared header files
140+
and referenced in multiple translation units. Our understanding is that
141+
`clang-tidy` processes each translation unit independently, so the
142+
`readability-identifer-naming` check generates a warning at the definition and
143+
a fix to rename all the references in _that_ translation unit. When
144+
`clang-tidy` aggregates its warnings across translation units, it
145+
[deduplicates them by
146+
location](https://github.com/llvm/llvm-project/blob/5de09ef02e24d234d9fc0cd1c6dfe18a1bb784b0/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp#L732)
147+
and retains the fix from an arbitrary one of the duplicate warnings rather
148+
than merging the fixes. The result is that only the references to the element
149+
in an arbitrary one of the translation units that includes its definition get
150+
renamed: a fundamental design flaw.
151+
152+
The upshot is that you're probably better off excluding
153+
`readability-identifier-naming` from your `clang-tidy --fix` pass, running a
154+
second pass without `--fix`, and fixing the `readability-identifier-naming`
155+
warnings with a tool that handles multiple translation units properly (such as
156+
a `clangd`-based IDE) along with the warnings that don't come with fixes.
144157

145158
- `readability-identifier-naming` may introduce a name collision. This may lead
146159
to an error on one of the colliding definitions, an error on a reference that

clang/include/clang/3C/3C.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
#ifndef LLVM_CLANG_3C_3C_H
1616
#define LLVM_CLANG_3C_3C_H
1717

18-
#include "3CInteractiveData.h"
19-
#include "ConstraintVariables.h"
20-
#include "PersistentSourceLoc.h"
21-
#include "ProgramInfo.h"
18+
#include "clang/3C/3CInteractiveData.h"
19+
#include "clang/3C/ConstraintVariables.h"
20+
#include "clang/3C/PersistentSourceLoc.h"
21+
#include "clang/3C/ProgramInfo.h"
2222
#include "clang/Tooling/CommonOptionsParser.h"
2323
#include <mutex>
2424

@@ -99,10 +99,10 @@ class _3CInterface {
9999
// datatype that is accepted in our codebase
100100
// (https://llvm.org/docs/ProgrammersManual.html#fallible-constructors) seems
101101
// too unwieldy to use right now.
102-
static std::unique_ptr<_3CInterface> create(
103-
const struct _3COptions &CCopt,
104-
const std::vector<std::string> &SourceFileList,
105-
clang::tooling::CompilationDatabase *CompDB);
102+
static std::unique_ptr<_3CInterface>
103+
create(const struct _3COptions &CCopt,
104+
const std::vector<std::string> &SourceFileList,
105+
clang::tooling::CompilationDatabase *CompDB);
106106

107107
// Constraint Building.
108108

clang/include/clang/3C/3CInteractiveData.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#ifndef LLVM_CLANG_3C_3CINTERACTIVEDATA_H
1414
#define LLVM_CLANG_3C_3CINTERACTIVEDATA_H
1515

16-
#include "ConstraintVariables.h"
17-
#include "PersistentSourceLoc.h"
16+
#include "clang/3C/ConstraintVariables.h"
17+
#include "clang/3C/PersistentSourceLoc.h"
1818

1919
// Source info and reason for each wild pointer.
2020
class WildPointerInferenceInfo {

clang/include/clang/3C/ABounds.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
#ifndef LLVM_CLANG_3C_ABOUNDS_H
1414
#define LLVM_CLANG_3C_ABOUNDS_H
1515

16-
#include "ProgramVar.h"
17-
#include <clang/AST/Decl.h>
18-
#include <clang/AST/Expr.h>
16+
#include "clang/3C/ProgramVar.h"
17+
#include "clang/AST/Decl.h"
18+
#include "clang/AST/Expr.h"
1919

2020
using namespace clang;
2121

clang/include/clang/3C/AVarBoundsInfo.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
// This file contains the bounds information about various ARR atoms.
1010
//
1111
//===----------------------------------------------------------------------===//
12+
1213
#ifndef LLVM_CLANG_3C_AVARBOUNDSINFO_H
1314
#define LLVM_CLANG_3C_AVARBOUNDSINFO_H
1415

15-
#include "ABounds.h"
16-
#include "AVarGraph.h"
17-
#include "ProgramVar.h"
16+
#include "clang/3C/ABounds.h"
17+
#include "clang/3C/AVarGraph.h"
1818
#include "clang/3C/ConstraintVariables.h"
1919
#include "clang/3C/PersistentSourceLoc.h"
20+
#include "clang/3C/ProgramVar.h"
2021
#include "clang/AST/Decl.h"
2122

2223
class ProgramInfo;

clang/include/clang/3C/AVarGraph.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#ifndef LLVM_CLANG_3C_AVARGRAPH_H
1414
#define LLVM_CLANG_3C_AVARGRAPH_H
1515

16-
#include "ABounds.h"
17-
#include "ConstraintsGraph.h"
16+
#include "clang/3C/ABounds.h"
17+
#include "clang/3C/ConstraintsGraph.h"
1818

1919
// Graph that keeps tracks of direct assignments between various variables.
2020
class AVarGraph : public DataGraph<BoundsKey> {

clang/include/clang/3C/ArrayBoundsInferenceConsumer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#ifndef LLVM_CLANG_3C_ARRAYBOUNDSINFERENCECONSUMER_H
1313
#define LLVM_CLANG_3C_ARRAYBOUNDSINFERENCECONSUMER_H
1414

15-
#include "ProgramInfo.h"
15+
#include "clang/3C/ProgramInfo.h"
1616
#include "clang/AST/ASTConsumer.h"
1717
#include "clang/AST/StmtVisitor.h"
1818
#include "clang/Analysis/Analyses/Dominators.h"

clang/include/clang/3C/CastPlacement.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,30 @@
1313
#define LLVM_CLANG_3C_CASTPLACEMENT_H
1414

1515
#include "clang/3C/ConstraintResolver.h"
16+
#include "clang/3C/RewriteUtils.h"
1617
#include "clang/AST/RecursiveASTVisitor.h"
17-
#include "RewriteUtils.h"
1818

1919
// Locates expressions which are children of explicit cast expressions after
2020
// ignoring any intermediate implicit expressions introduced in the clang AST.
2121
class CastLocatorVisitor : public RecursiveASTVisitor<CastLocatorVisitor> {
2222
public:
23-
explicit CastLocatorVisitor(ASTContext *C) : Context(C) {}
23+
// This visitor happens to not use the ASTContext itself.
24+
explicit CastLocatorVisitor(ASTContext *C) {}
2425

2526
bool VisitCastExpr(CastExpr *C);
2627

2728
std::set<Expr *> &getExprsWithCast() { return ExprsWithCast; }
2829

2930
private:
30-
ASTContext *Context;
3131
std::set<Expr *> ExprsWithCast;
3232
};
3333

3434
class CastPlacementVisitor : public RecursiveASTVisitor<CastPlacementVisitor> {
3535
public:
36-
explicit CastPlacementVisitor
37-
(ASTContext *C, ProgramInfo &I, Rewriter &R, std::set<Expr *> &EWC)
38-
: Context(C), Info(I), Writer(R), CR(Info, Context), ABRewriter(I),
39-
ExprsWithCast(EWC) {}
36+
explicit CastPlacementVisitor(ASTContext *C, ProgramInfo &I, Rewriter &R,
37+
std::set<Expr *> &EWC)
38+
: Context(C), Info(I), Writer(R), CR(Info, Context), ABRewriter(I),
39+
ExprsWithCast(EWC) {}
4040

4141
bool VisitCallExpr(CallExpr *C);
4242

@@ -55,13 +55,12 @@ class CastPlacementVisitor : public RecursiveASTVisitor<CastPlacementVisitor> {
5555
CAST_TO_WILD // A standard C explicit cast required (checked -> wild)
5656
};
5757

58-
CastNeeded needCasting(ConstraintVariable *SrcInt,
59-
ConstraintVariable *SrcExt,
58+
CastNeeded needCasting(ConstraintVariable *SrcInt, ConstraintVariable *SrcExt,
6059
ConstraintVariable *DstInt,
6160
ConstraintVariable *DstExt);
6261

63-
std::pair<std::string, std::string>
64-
getCastString(ConstraintVariable *Dst, CastNeeded CastKind);
62+
std::pair<std::string, std::string> getCastString(ConstraintVariable *Dst,
63+
CastNeeded CastKind);
6564

6665
void surroundByCast(ConstraintVariable *Dst, CastNeeded CastKind, Expr *E);
6766
void reportCastInsertionFailure(Expr *E, const std::string &CastStr);

clang/include/clang/3C/CheckedRegions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#ifndef LLVM_CLANG_3C_CHECKEDREGIONS_H
1414
#define LLVM_CLANG_3C_CHECKEDREGIONS_H
1515

16-
#include "ProgramInfo.h"
16+
#include "clang/3C/ProgramInfo.h"
1717
#include "clang/AST/ASTContext.h"
1818
#include "clang/AST/Decl.h"
1919
#include "clang/AST/Stmt.h"

clang/include/clang/3C/ConstraintBuilder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#ifndef LLVM_CLANG_3C_CONSTRAINTBUILDER_H
1212
#define LLVM_CLANG_3C_CONSTRAINTBUILDER_H
1313

14-
#include "ProgramInfo.h"
15-
#include "TypeVariableAnalysis.h"
14+
#include "clang/3C/ProgramInfo.h"
15+
#include "clang/3C/TypeVariableAnalysis.h"
1616
#include "clang/AST/ASTConsumer.h"
1717

1818
class ConstraintBuilderConsumer : public clang::ASTConsumer {

0 commit comments

Comments
 (0)