Skip to content

Commit 438bedc

Browse files
committed
Merge from 'master' to 'sycl-web' (#250)
CONFLICT (content): Merge conflict in clang/lib/CodeGen/CGExpr.cpp
2 parents 8e10e63 + 4e2ce22 commit 438bedc

File tree

686 files changed

+20548
-4845
lines changed

Some content is hidden

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

686 files changed

+20548
-4845
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//===--- BadSignalToKillThreadCheck.cpp - clang-tidy ---------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "BadSignalToKillThreadCheck.h"
10+
#include "clang/AST/ASTContext.h"
11+
#include "clang/ASTMatchers/ASTMatchFinder.h"
12+
13+
using namespace clang::ast_matchers;
14+
15+
namespace clang {
16+
namespace tidy {
17+
namespace bugprone {
18+
19+
void BadSignalToKillThreadCheck::registerMatchers(MatchFinder *Finder) {
20+
Finder->addMatcher(
21+
callExpr(allOf(callee(functionDecl(hasName("::pthread_kill"))),
22+
argumentCountIs(2)),
23+
hasArgument(1, integerLiteral().bind("integer-literal")))
24+
.bind("thread-kill"),
25+
this);
26+
}
27+
28+
static Preprocessor *PP;
29+
30+
void BadSignalToKillThreadCheck::check(const MatchFinder::MatchResult &Result) {
31+
const auto IsSigterm = [](const auto &KeyValue) -> bool {
32+
return KeyValue.first->getName() == "SIGTERM";
33+
};
34+
const auto TryExpandAsInteger =
35+
[](Preprocessor::macro_iterator It) -> Optional<unsigned> {
36+
if (It == PP->macro_end())
37+
return llvm::None;
38+
const MacroInfo *MI = PP->getMacroInfo(It->first);
39+
const Token &T = MI->tokens().back();
40+
StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
41+
42+
llvm::APInt IntValue;
43+
constexpr unsigned AutoSenseRadix = 0;
44+
if (ValueStr.getAsInteger(AutoSenseRadix, IntValue))
45+
return llvm::None;
46+
return IntValue.getZExtValue();
47+
};
48+
49+
const auto SigtermMacro = llvm::find_if(PP->macros(), IsSigterm);
50+
51+
if (!SigtermValue && !(SigtermValue = TryExpandAsInteger(SigtermMacro)))
52+
return;
53+
54+
const auto *MatchedExpr = Result.Nodes.getNodeAs<Expr>("thread-kill");
55+
const auto *MatchedIntLiteral =
56+
Result.Nodes.getNodeAs<IntegerLiteral>("integer-literal");
57+
if (MatchedIntLiteral->getValue() == *SigtermValue) {
58+
diag(MatchedExpr->getBeginLoc(),
59+
"thread should not be terminated by raising the 'SIGTERM' signal");
60+
}
61+
}
62+
63+
void BadSignalToKillThreadCheck::registerPPCallbacks(
64+
const SourceManager &SM, Preprocessor *pp, Preprocessor *ModuleExpanderPP) {
65+
PP = pp;
66+
}
67+
68+
} // namespace bugprone
69+
} // namespace tidy
70+
} // namespace clang
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===--- BadSignalToKillThreadCheck.h - clang-tidy --------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_BADSIGNALTOKILLTHREADCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_BADSIGNALTOKILLTHREADCHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang {
15+
namespace tidy {
16+
namespace bugprone {
17+
18+
/// Finds ``pthread_kill`` function calls when thread is terminated by
19+
/// ``SIGTERM`` signal.
20+
/// For the user-facing documentation see:
21+
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-bad-signal-to-kill-thread.html
22+
class BadSignalToKillThreadCheck : public ClangTidyCheck {
23+
public:
24+
BadSignalToKillThreadCheck(StringRef Name, ClangTidyContext *Context)
25+
: ClangTidyCheck(Name, Context) {}
26+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
27+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
28+
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
29+
Preprocessor *ModuleExpanderPP) override;
30+
Optional<unsigned> SigtermValue;
31+
};
32+
33+
} // namespace bugprone
34+
} // namespace tidy
35+
} // namespace clang
36+
37+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_BADSIGNALTOKILLTHREADCHECK_H

clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "../cppcoreguidelines/NarrowingConversionsCheck.h"
1313
#include "ArgumentCommentCheck.h"
1414
#include "AssertSideEffectCheck.h"
15+
#include "BadSignalToKillThreadCheck.h"
1516
#include "BoolPointerImplicitConversionCheck.h"
1617
#include "BranchCloneCheck.h"
1718
#include "CopyConstructorInitCheck.h"
@@ -68,6 +69,8 @@ class BugproneModule : public ClangTidyModule {
6869
"bugprone-argument-comment");
6970
CheckFactories.registerCheck<AssertSideEffectCheck>(
7071
"bugprone-assert-side-effect");
72+
CheckFactories.registerCheck<BadSignalToKillThreadCheck>(
73+
"bugprone-bad-signal-to-kill-thread");
7174
CheckFactories.registerCheck<BoolPointerImplicitConversionCheck>(
7275
"bugprone-bool-pointer-implicit-conversion");
7376
CheckFactories.registerCheck<BranchCloneCheck>(

clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS support)
33
add_clang_library(clangTidyBugproneModule
44
ArgumentCommentCheck.cpp
55
AssertSideEffectCheck.cpp
6+
BadSignalToKillThreadCheck.cpp
67
BoolPointerImplicitConversionCheck.cpp
78
BranchCloneCheck.cpp
89
BugproneTidyModule.cpp

clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "../ClangTidyModule.h"
1111
#include "../ClangTidyModuleRegistry.h"
1212
#include "../bugprone/UnhandledSelfAssignmentCheck.h"
13+
#include "../bugprone/BadSignalToKillThreadCheck.h"
1314
#include "../google/UnnamedNamespaceInHeaderCheck.h"
1415
#include "../misc/NewDeleteOverloadsCheck.h"
1516
#include "../misc/NonCopyableObjects.h"
@@ -82,6 +83,9 @@ class CERTModule : public ClangTidyModule {
8283
CheckFactories.registerCheck<LimitedRandomnessCheck>("cert-msc30-c");
8384
CheckFactories.registerCheck<ProperlySeededRandomGeneratorCheck>(
8485
"cert-msc32-c");
86+
// POS
87+
CheckFactories.registerCheck<bugprone::BadSignalToKillThreadCheck>(
88+
"cert-pos44-c");
8589
}
8690

8791
ClangTidyOptions getModuleOptions() override {

clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void TransformerClangTidyCheck::check(
8585
if (Transformations->empty())
8686
return;
8787

88-
Expected<std::string> Explanation = Case.Explanation(Result);
88+
Expected<std::string> Explanation = Case.Explanation->eval(Result);
8989
if (!Explanation) {
9090
llvm::errs() << "Error in explanation: "
9191
<< llvm::toString(Explanation.takeError()) << "\n";

clang-tools-extra/clangd/AST.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,13 @@ llvm::Optional<SymbolID> getSymbolID(const Decl *D) {
203203
return SymbolID(USR);
204204
}
205205

206-
llvm::Optional<SymbolID> getSymbolID(const IdentifierInfo &II,
206+
llvm::Optional<SymbolID> getSymbolID(const llvm::StringRef MacroName,
207207
const MacroInfo *MI,
208208
const SourceManager &SM) {
209209
if (MI == nullptr)
210210
return None;
211211
llvm::SmallString<128> USR;
212-
if (index::generateUSRForMacro(II.getName(), MI->getDefinitionLoc(), SM, USR))
212+
if (index::generateUSRForMacro(MacroName, MI->getDefinitionLoc(), SM, USR))
213213
return None;
214214
return SymbolID(USR);
215215
}

clang-tools-extra/clangd/AST.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "clang/AST/Decl.h"
1818
#include "clang/Basic/SourceLocation.h"
1919
#include "clang/Lex/MacroInfo.h"
20+
#include "llvm/ADT/StringRef.h"
2021

2122
namespace clang {
2223
class SourceManager;
@@ -69,7 +70,7 @@ llvm::Optional<SymbolID> getSymbolID(const Decl *D);
6970
/// macro (e.g. a change in definition offset can result in a different USR). We
7071
/// could change these semantics in the future by reimplementing this funcure
7172
/// (e.g. avoid USR for macros).
72-
llvm::Optional<SymbolID> getSymbolID(const IdentifierInfo &II,
73+
llvm::Optional<SymbolID> getSymbolID(const llvm::StringRef MacroName,
7374
const MacroInfo *MI,
7475
const SourceManager &SM);
7576

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ llvm::Optional<SymbolID> getSymbolID(const CodeCompletionResult &R,
492492
return clang::clangd::getSymbolID(R.Declaration);
493493
}
494494
case CodeCompletionResult::RK_Macro:
495-
return clang::clangd::getSymbolID(*R.Macro, R.MacroDefInfo, SM);
495+
return clang::clangd::getSymbolID(R.Macro->getName(), R.MacroDefInfo, SM);
496496
case CodeCompletionResult::RK_Keyword:
497497
return None;
498498
}

clang-tools-extra/clangd/clients/clangd-vscode/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clang-tools-extra/clangd/clients/clangd-vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-clangd",
33
"displayName": "vscode-clangd",
44
"description": "Clang Language Server",
5-
"version": "0.0.18",
5+
"version": "0.0.19",
66
"publisher": "llvm-vs-code-extensions",
77
"homepage": "https://clang.llvm.org/extra/clangd.html",
88
"engines": {

clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,17 @@ export class SemanticHighlightingFeature implements vscodelc.StaticFeature {
114114
this.loadCurrentTheme();
115115
// Event handling for handling with TextDocuments/Editors lifetimes.
116116
this.subscriptions.push(vscode.window.onDidChangeVisibleTextEditors(
117-
(editors: vscode.TextEditor[]) =>
118-
editors.forEach((e) => this.highlighter.applyHighlights(
119-
e.document.uri.toString()))));
117+
(editors: vscode.TextEditor[]) => editors.forEach(
118+
(e) => this.highlighter.applyHighlights(e.document.uri))));
120119
this.subscriptions.push(vscode.workspace.onDidCloseTextDocument(
121-
(doc) => this.highlighter.removeFileHighlightings(doc.uri.toString())));
120+
(doc) => this.highlighter.removeFileHighlightings(doc.uri)));
122121
}
123122

124123
handleNotification(params: SemanticHighlightingParams) {
125124
const lines: SemanticHighlightingLine[] = params.lines.map(
126125
(line) => ({line : line.line, tokens : decodeTokens(line.tokens)}));
127-
this.highlighter.highlight(params.textDocument.uri, lines);
126+
this.highlighter.highlight(vscode.Uri.parse(params.textDocument.uri),
127+
lines);
128128
}
129129
// Disposes of all disposable resources used by this object.
130130
public dispose() {
@@ -199,19 +199,21 @@ export class Highlighter {
199199
// Adds incremental highlightings to the current highlightings for the file
200200
// with fileUri. Also applies the highlightings to any associated
201201
// TextEditor(s).
202-
public highlight(fileUri: string,
202+
public highlight(fileUri: vscode.Uri,
203203
highlightingLines: SemanticHighlightingLine[]) {
204-
if (!this.files.has(fileUri)) {
205-
this.files.set(fileUri, new Map());
204+
const fileUriStr = fileUri.toString();
205+
if (!this.files.has(fileUriStr)) {
206+
this.files.set(fileUriStr, new Map());
206207
}
207-
const fileHighlightings = this.files.get(fileUri);
208+
const fileHighlightings = this.files.get(fileUriStr);
208209
highlightingLines.forEach((line) => fileHighlightings.set(line.line, line));
209210
this.applyHighlights(fileUri);
210211
}
211212

212213
// Applies all the highlightings currently stored for a file with fileUri.
213-
public applyHighlights(fileUri: string) {
214-
if (!this.files.has(fileUri))
214+
public applyHighlights(fileUri: vscode.Uri) {
215+
const fileUriStr = fileUri.toString();
216+
if (!this.files.has(fileUriStr))
215217
// There are no highlightings for this file, must return early or will get
216218
// out of bounds when applying the decorations below.
217219
return;
@@ -224,35 +226,35 @@ export class Highlighter {
224226
// TextEditorDecorationType is used per scope.
225227
const ranges = this.getDecorationRanges(fileUri);
226228
vscode.window.visibleTextEditors.forEach((e) => {
227-
if (e.document.uri.toString() !== fileUri)
229+
if (e.document.uri.toString() !== fileUriStr)
228230
return;
229231
this.decorationTypes.forEach((d, i) => e.setDecorations(d, ranges[i]));
230232
});
231233
}
232234

233235
// Called when a text document is closed. Removes any highlighting entries for
234236
// the text document that was closed.
235-
public removeFileHighlightings(fileUri: string) {
237+
public removeFileHighlightings(fileUri: vscode.Uri) {
236238
// If there exists no entry the call to delete just returns false.
237-
this.files.delete(fileUri);
239+
this.files.delete(fileUri.toString());
238240
}
239241

240242
// Gets the uris as strings for the currently visible text editors.
241-
protected getVisibleTextEditorUris(): string[] {
242-
return vscode.window.visibleTextEditors.map((e) =>
243-
e.document.uri.toString());
243+
protected getVisibleTextEditorUris(): vscode.Uri[] {
244+
return vscode.window.visibleTextEditors.map((e) => e.document.uri);
244245
}
245246

246247
// Returns the ranges that should be used when decorating. Index i in the
247248
// range array has the decoration type at index i of this.decorationTypes.
248-
protected getDecorationRanges(fileUri: string): vscode.Range[][] {
249-
if (!this.files.has(fileUri))
249+
protected getDecorationRanges(fileUri: vscode.Uri): vscode.Range[][] {
250+
const fileUriStr = fileUri.toString();
251+
if (!this.files.has(fileUriStr))
250252
// this.files should always have an entry for fileUri if we are here. But
251253
// if there isn't one we don't want to crash the extension. This is also
252254
// useful for tests.
253255
return [];
254256
const lines: SemanticHighlightingLine[] =
255-
Array.from(this.files.get(fileUri).values());
257+
Array.from(this.files.get(fileUriStr).values());
256258
const decorations: vscode.Range[][] = this.decorationTypes.map(() => []);
257259
lines.forEach((line) => {
258260
line.tokens.forEach((token) => {

0 commit comments

Comments
 (0)