Skip to content

Commit cdabc42

Browse files
Merge from 'master' to 'sycl-web' (#1)
CONFLICT (content): Merge conflict in libclc/generic/lib/gen_convert.py CONFLICT (content): Merge conflict in libclc/CMakeLists.txt
2 parents 6b25aa6 + 1c1a810 commit cdabc42

File tree

355 files changed

+13200
-5607
lines changed

Some content is hidden

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

355 files changed

+13200
-5607
lines changed

clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.cpp

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,17 @@ namespace clang {
1818
namespace tidy {
1919
namespace android {
2020

21-
namespace {
22-
AST_MATCHER(BinaryOperator, isRHSATempFailureRetryArg) {
23-
if (!Node.getBeginLoc().isMacroID())
24-
return false;
25-
26-
const SourceManager &SM = Finder->getASTContext().getSourceManager();
27-
if (!SM.isMacroArgExpansion(Node.getRHS()->IgnoreParenCasts()->getBeginLoc()))
28-
return false;
29-
30-
const LangOptions &Opts = Finder->getASTContext().getLangOpts();
31-
SourceLocation LocStart = Node.getBeginLoc();
32-
while (LocStart.isMacroID()) {
33-
SourceLocation Invocation = SM.getImmediateMacroCallerLoc(LocStart);
34-
Token Tok;
35-
if (!Lexer::getRawToken(SM.getSpellingLoc(Invocation), Tok, SM, Opts,
36-
/*IgnoreWhiteSpace=*/true)) {
37-
if (Tok.getKind() == tok::raw_identifier &&
38-
Tok.getRawIdentifier() == "TEMP_FAILURE_RETRY")
39-
return true;
40-
}
21+
ComparisonInTempFailureRetryCheck::ComparisonInTempFailureRetryCheck(
22+
StringRef Name, ClangTidyContext *Context)
23+
: ClangTidyCheck(Name, Context),
24+
RawRetryList(Options.get("RetryMacros", "TEMP_FAILURE_RETRY")) {
25+
StringRef(RawRetryList).split(RetryMacros, ",", -1, false);
26+
}
4127

42-
LocStart = Invocation;
43-
}
44-
return false;
28+
void ComparisonInTempFailureRetryCheck::storeOptions(
29+
ClangTidyOptions::OptionMap &Opts) {
30+
Options.store(Opts, "RetryMacros", RawRetryList);
4531
}
46-
} // namespace
4732

4833
void ComparisonInTempFailureRetryCheck::registerMatchers(MatchFinder *Finder) {
4934
// Both glibc's and Bionic's TEMP_FAILURE_RETRY macros structurally look like:
@@ -63,15 +48,43 @@ void ComparisonInTempFailureRetryCheck::registerMatchers(MatchFinder *Finder) {
6348
Finder->addMatcher(
6449
binaryOperator(hasOperatorName("="),
6550
hasRHS(ignoringParenCasts(
66-
binaryOperator(isComparisonOperator()).bind("binop"))),
67-
isRHSATempFailureRetryArg()),
51+
binaryOperator(isComparisonOperator()).bind("inner"))))
52+
.bind("outer"),
6853
this);
6954
}
7055

7156
void ComparisonInTempFailureRetryCheck::check(
7257
const MatchFinder::MatchResult &Result) {
73-
const auto &BinOp = *Result.Nodes.getNodeAs<BinaryOperator>("binop");
74-
diag(BinOp.getOperatorLoc(), "top-level comparison in TEMP_FAILURE_RETRY");
58+
StringRef RetryMacroName;
59+
const auto &Node = *Result.Nodes.getNodeAs<BinaryOperator>("outer");
60+
if (!Node.getBeginLoc().isMacroID())
61+
return;
62+
63+
const SourceManager &SM = *Result.SourceManager;
64+
if (!SM.isMacroArgExpansion(Node.getRHS()->IgnoreParenCasts()->getBeginLoc()))
65+
return;
66+
67+
const LangOptions &Opts = Result.Context->getLangOpts();
68+
SourceLocation LocStart = Node.getBeginLoc();
69+
while (LocStart.isMacroID()) {
70+
SourceLocation Invocation = SM.getImmediateMacroCallerLoc(LocStart);
71+
Token Tok;
72+
if (!Lexer::getRawToken(SM.getSpellingLoc(Invocation), Tok, SM, Opts,
73+
/*IgnoreWhiteSpace=*/true)) {
74+
if (Tok.getKind() == tok::raw_identifier &&
75+
llvm::is_contained(RetryMacros, Tok.getRawIdentifier())) {
76+
RetryMacroName = Tok.getRawIdentifier();
77+
break;
78+
}
79+
}
80+
81+
LocStart = Invocation;
82+
}
83+
if (RetryMacroName.empty())
84+
return;
85+
86+
const auto &Inner = *Result.Nodes.getNodeAs<BinaryOperator>("inner");
87+
diag(Inner.getOperatorLoc(), "top-level comparison in %0") << RetryMacroName;
7588

7689
// FIXME: FixIts would be nice, but potentially nontrivial when nested macros
7790
// happen, e.g. `TEMP_FAILURE_RETRY(IS_ZERO(foo()))`

clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.h

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

1212
#include "../ClangTidyCheck.h"
13+
#include "llvm/ADT/SmallVector.h"
14+
#include "llvm/ADT/StringRef.h"
15+
#include <string>
1316

1417
namespace clang {
1518
namespace tidy {
@@ -22,10 +25,14 @@ namespace android {
2225
/// TEMP_FAILURE_RETRY is a macro provided by both glibc and Bionic.
2326
class ComparisonInTempFailureRetryCheck : public ClangTidyCheck {
2427
public:
25-
ComparisonInTempFailureRetryCheck(StringRef Name, ClangTidyContext *Context)
26-
: ClangTidyCheck(Name, Context) {}
28+
ComparisonInTempFailureRetryCheck(StringRef Name, ClangTidyContext *Context);
29+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
2730
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
2831
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
32+
33+
private:
34+
const std::string RawRetryList;
35+
SmallVector<StringRef, 5> RetryMacros;
2936
};
3037

3138
} // namespace android

clang-tools-extra/clangd/URI.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ bool shouldEscape(unsigned char C) {
111111
/// - Reserved characters always escaped with exceptions like '/'.
112112
/// - All other characters are escaped.
113113
void percentEncode(llvm::StringRef Content, std::string &Out) {
114-
std::string Result;
115114
for (unsigned char C : Content)
116115
if (shouldEscape(C)) {
117116
Out.push_back('%');

clang-tools-extra/clangd/quality/CompletionModelCodegen.py

Lines changed: 60 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Code generator for Code Completion Model Inference.
22
33
Tool runs on the Decision Forest model defined in {model} directory.
4-
It generates two files: {output_dir}/{filename}.h and {output_dir}/{filename}.cpp
4+
It generates two files: {output_dir}/{filename}.h and {output_dir}/{filename}.cpp
55
The generated files defines the Example class named {cpp_class} having all the features as class members.
66
The generated runtime provides an `Evaluate` function which can be used to score a code completion candidate.
77
"""
@@ -39,34 +39,32 @@ def header_guard(filename):
3939

4040

4141
def boost_node(n, label, next_label):
42-
"""Returns code snippet for a leaf/boost node.
43-
Adds value of leaf to the score and jumps to the root of the next tree."""
44-
return "%s: Score += %s; goto %s;" % (
45-
label, n['score'], next_label)
42+
"""Returns code snippet for a leaf/boost node."""
43+
return "%s: return %s;" % (label, n['score'])
4644

4745

4846
def if_greater_node(n, label, next_label):
4947
"""Returns code snippet for a if_greater node.
50-
Jumps to true_label if the Example feature (NUMBER) is greater than the threshold.
51-
Comparing integers is much faster than comparing floats. Assuming floating points
48+
Jumps to true_label if the Example feature (NUMBER) is greater than the threshold.
49+
Comparing integers is much faster than comparing floats. Assuming floating points
5250
are represented as IEEE 754, it order-encodes the floats to integers before comparing them.
5351
Control falls through if condition is evaluated to false."""
5452
threshold = n["threshold"]
55-
return "%s: if (E.%s >= %s /*%s*/) goto %s;" % (
56-
label, n['feature'], order_encode(threshold), threshold, next_label)
53+
return "%s: if (E.get%s() >= %s /*%s*/) goto %s;" % (
54+
label, n['feature'], order_encode(threshold), threshold, next_label)
5755

5856

5957
def if_member_node(n, label, next_label):
6058
"""Returns code snippet for a if_member node.
61-
Jumps to true_label if the Example feature (ENUM) is present in the set of enum values
59+
Jumps to true_label if the Example feature (ENUM) is present in the set of enum values
6260
described in the node.
6361
Control falls through if condition is evaluated to false."""
6462
members = '|'.join([
6563
"BIT(%s_type::%s)" % (n['feature'], member)
6664
for member in n["set"]
6765
])
68-
return "%s: if (E.%s & (%s)) goto %s;" % (
69-
label, n['feature'], members, next_label)
66+
return "%s: if (E.get%s() & (%s)) goto %s;" % (
67+
label, n['feature'], members, next_label)
7068

7169

7270
def node(n, label, next_label):
@@ -94,8 +92,6 @@ def tree(t, tree_num, node_num):
9492
"""
9593
label = "t%d_n%d" % (tree_num, node_num)
9694
code = []
97-
if node_num == 0:
98-
code.append("t%d:" % tree_num)
9995

10096
if t["operation"] == "boost":
10197
code.append(node(t, label=label, next_label="t%d" % (tree_num + 1)))
@@ -119,13 +115,15 @@ def gen_header_code(features_json, cpp_class, filename):
119115
"""Returns code for header declaring the inference runtime.
120116
121117
Declares the Example class named {cpp_class} inside relevant namespaces.
122-
The Example class contains all the features as class members. This
118+
The Example class contains all the features as class members. This
123119
class can be used to represent a code completion candidate.
124120
Provides `float Evaluate()` function which can be used to score the Example.
125121
"""
126122
setters = []
123+
getters = []
127124
for f in features_json:
128125
feature = f["name"]
126+
129127
if f["kind"] == "NUMBER":
130128
# Floats are order-encoded to integers for faster comparison.
131129
setters.append(
@@ -138,8 +136,15 @@ class can be used to represent a code completion candidate.
138136
raise ValueError("Unhandled feature type.", f["kind"])
139137

140138
# Class members represent all the features of the Example.
141-
class_members = ["uint32_t %s = 0;" % f['name'] for f in features_json]
142-
139+
class_members = [
140+
"uint32_t %s = 0;" % f['name']
141+
for f in features_json
142+
]
143+
getters = [
144+
"LLVM_ATTRIBUTE_ALWAYS_INLINE uint32_t get%s() const { return %s; }"
145+
% (f['name'], f['name'])
146+
for f in features_json
147+
]
143148
nline = "\n "
144149
guard = header_guard(filename)
145150
return """#ifndef %s
@@ -150,6 +155,10 @@ class can be used to represent a code completion candidate.
150155
%s
151156
class %s {
152157
public:
158+
// Setters.
159+
%s
160+
161+
// Getters.
153162
%s
154163
155164
private:
@@ -158,18 +167,16 @@ class %s {
158167
// Produces an integer that sorts in the same order as F.
159168
// That is: a < b <==> orderEncode(a) < orderEncode(b).
160169
static uint32_t OrderEncode(float F);
161-
friend float Evaluate(const %s&);
162170
};
163171
164-
// The function may have large number of lines of code. MSAN
165-
// build times out in such case.
166-
LLVM_NO_SANITIZE("memory")
167172
float Evaluate(const %s&);
168173
%s
169174
#endif // %s
170-
""" % (guard, guard, cpp_class.ns_begin(), cpp_class.name, nline.join(setters),
171-
nline.join(class_members), cpp_class.name, cpp_class.name,
172-
cpp_class.ns_end(), guard)
175+
""" % (guard, guard, cpp_class.ns_begin(), cpp_class.name,
176+
nline.join(setters),
177+
nline.join(getters),
178+
nline.join(class_members),
179+
cpp_class.name, cpp_class.ns_end(), guard)
173180

174181

175182
def order_encode(v):
@@ -182,21 +189,33 @@ def order_encode(v):
182189

183190

184191
def evaluate_func(forest_json, cpp_class):
185-
"""Generates code for `float Evaluate(const {Example}&)` function.
186-
The generated function can be used to score an Example."""
187-
code = "float Evaluate(const %s& E) {\n" % cpp_class.name
188-
lines = []
189-
lines.append("float Score = 0;")
192+
"""Generates evaluation functions for each tree and combines them in
193+
`float Evaluate(const {Example}&)` function. This function can be
194+
used to score an Example."""
195+
196+
code = ""
197+
198+
# Generate evaluation function of each tree.
199+
code += "namespace {\n"
190200
tree_num = 0
191201
for tree_json in forest_json:
192-
lines.extend(tree(tree_json, tree_num=tree_num, node_num=0)[0])
193-
lines.append("")
202+
code += "LLVM_ATTRIBUTE_NOINLINE float EvaluateTree%d(const %s& E) {\n" % (tree_num, cpp_class.name)
203+
code += " " + \
204+
"\n ".join(
205+
tree(tree_json, tree_num=tree_num, node_num=0)[0]) + "\n"
206+
code += "}\n\n"
194207
tree_num += 1
208+
code += "} // namespace\n\n"
209+
210+
# Combine the scores of all trees in the final function.
211+
# MSAN will timeout if these functions are inlined.
212+
code += "float Evaluate(const %s& E) {\n" % cpp_class.name
213+
code += " float Score = 0;\n"
214+
for tree_num in range(len(forest_json)):
215+
code += " Score += EvaluateTree%d(E);\n" % tree_num
216+
code += " return Score;\n"
217+
code += "}\n"
195218

196-
lines.append("t%s: // No such tree." % len(forest_json))
197-
lines.append("return Score;")
198-
code += " " + "\n ".join(lines)
199-
code += "\n}"
200219
return code
201220

202221

@@ -218,9 +237,9 @@ def gen_cpp_code(forest_json, features_json, filename, cpp_class):
218237

219238
# using-decl for ENUM features.
220239
using_decls = "\n".join("using %s_type = %s;" % (
221-
feature['name'], feature['type'])
222-
for feature in features_json
223-
if feature["kind"] == "ENUM")
240+
feature['name'], feature['type'])
241+
for feature in features_json
242+
if feature["kind"] == "ENUM")
224243
nl = "\n"
225244
return """%s
226245
@@ -287,7 +306,9 @@ def main():
287306

288307
with open(header_file, 'w+t') as output_h:
289308
output_h.write(gen_header_code(
290-
features_json=features_json, cpp_class=cpp_class, filename=filename))
309+
features_json=features_json,
310+
cpp_class=cpp_class,
311+
filename=filename))
291312

292313

293314
if __name__ == '__main__':
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: cp %s %t.cpp
2+
// RUN: not clangd -check=%t.cpp 2>&1 | FileCheck -strict-whitespace %s
3+
4+
// CHECK: Testing on source file {{.*}}check-fail.test
5+
// CHECK: internal (cc1) args are: -cc1
6+
// CHECK: Building preamble...
7+
// CHECK: [pp_file_not_found] Line {{.*}}: 'missing.h' file not found
8+
// CHECK: Building AST...
9+
// CHECK: Testing features at each token
10+
// CHECK: tweak: ExpandAutoType ==> FAIL
11+
// CHECK: All checks completed, 2 errors
12+
13+
#include "missing.h"
14+
auto x = []{};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# RUN: clangd -log=verbose -check 2>&1 | FileCheck -strict-whitespace %s
2+
3+
CHECK: Testing on source file {{.*}}test.cc
4+
CHECK: internal (cc1) args are: -cc1
5+
CHECK: Building preamble...
6+
CHECK: Built preamble
7+
CHECK: Building AST...
8+
CHECK: Testing features at each token
9+
CHECK-DAG: hover: false
10+
CHECK-DAG: hover: true
11+
CHECK-DAG: tweak: AddUsing
12+
CHECK: All checks completed, 0 errors
13+

clang-tools-extra/clangd/tool/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}/..)
33

44
add_clang_tool(clangd
55
ClangdMain.cpp
6+
Check.cpp
67
$<TARGET_OBJECTS:obj.clangDaemonTweaks>
78
)
89

0 commit comments

Comments
 (0)