Skip to content

Commit 7ce78ec

Browse files
committed
Merge remote-tracking branch 'intel_llvm/sycl-web' into llvmspirv_pulldown
2 parents 96e96c4 + 7c3a45a commit 7ce78ec

File tree

2,813 files changed

+954693
-13154
lines changed

Some content is hidden

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

2,813 files changed

+954693
-13154
lines changed

.mailmap

Lines changed: 1 addition & 0 deletions

bolt/lib/Core/BinarySection.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,20 @@ BinarySection::hash(const BinaryData &BD,
3939
if (Itr != Cache.end())
4040
return Itr->second;
4141

42-
Cache[&BD] = 0;
42+
hash_code Hash =
43+
hash_combine(hash_value(BD.getSize()), hash_value(BD.getSectionName()));
44+
45+
Cache[&BD] = Hash;
46+
47+
if (!containsRange(BD.getAddress(), BD.getSize()))
48+
return Hash;
4349

4450
uint64_t Offset = BD.getAddress() - getAddress();
4551
const uint64_t EndOffset = BD.getEndAddress() - getAddress();
4652
auto Begin = Relocations.lower_bound(Relocation{Offset, 0, 0, 0, 0});
4753
auto End = Relocations.upper_bound(Relocation{EndOffset, 0, 0, 0, 0});
4854
const StringRef Contents = getContents();
4955

50-
hash_code Hash =
51-
hash_combine(hash_value(BD.getSize()), hash_value(BD.getSectionName()));
52-
5356
while (Begin != End) {
5457
const Relocation &Rel = *Begin++;
5558
Hash = hash_combine(
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
--- !ELF
2+
FileHeader:
3+
Class: ELFCLASS64
4+
Data: ELFDATA2LSB
5+
Type: ET_EXEC
6+
Machine: EM_AARCH64
7+
Entry: 0x90
8+
ProgramHeaders:
9+
- Type: PT_LOAD
10+
Flags: [ PF_X, PF_R ]
11+
FirstSec: .rodata
12+
LastSec: .text
13+
Align: 0x10000
14+
Offset: 0x0
15+
Sections:
16+
- Name: .rodata
17+
Type: SHT_PROGBITS
18+
Flags: [ SHF_ALLOC ]
19+
Address: 0x78
20+
AddressAlign: 0x1
21+
Content: '7800000000000000'
22+
- Name: .dummy
23+
Type: SHT_PROGBITS
24+
Flags: [ SHF_ALLOC ]
25+
Address: 0x80
26+
AddressAlign: 0x1
27+
Content: '78000000000000009000000000000000'
28+
- Name: .text
29+
Type: SHT_PROGBITS
30+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
31+
Address: 0x90
32+
AddressAlign: 0x4
33+
Content: FF4300D11F2003D508FFFF10080140F9E80700F9A80B8052010000D4FF430091C0035FD6
34+
- Name: .rela.text
35+
Type: SHT_RELA
36+
Flags: [ SHF_INFO_LINK ]
37+
Link: .symtab
38+
AddressAlign: 0x8
39+
Info: .text
40+
Relocations:
41+
- Offset: 0x94
42+
Symbol: Symbol
43+
Type: R_AARCH64_ADR_GOT_PAGE
44+
- Offset: 0x98
45+
Symbol: Symbol
46+
Type: R_AARCH64_LD64_GOT_LO12_NC
47+
- Name: .rela.dummy
48+
Type: SHT_RELA
49+
Flags: [ SHF_INFO_LINK ]
50+
Link: .symtab
51+
AddressAlign: 0x8
52+
Info: .dummy
53+
Relocations:
54+
- Offset: 0x80
55+
Symbol: Symbol
56+
Type: R_AARCH64_ABS64
57+
- Offset: 0x88
58+
Symbol: _start
59+
Type: R_AARCH64_ABS64
60+
Symbols:
61+
- Name: tmp.c
62+
Type: STT_FILE
63+
Index: SHN_ABS
64+
- Name: '$x.0'
65+
Section: .text
66+
Value: 0x90
67+
- Name: '$d.1'
68+
Index: SHN_ABS
69+
- Name: .text
70+
Type: STT_SECTION
71+
Section: .text
72+
Value: 0x90
73+
- Name: _start
74+
Type: STT_FUNC
75+
Section: .text
76+
Binding: STB_GLOBAL
77+
Value: 0x90
78+
Size: 0x24
79+
- Name: Symbol
80+
Section: .rodata
81+
Binding: STB_GLOBAL
82+
Value: 0x78
83+
...

bolt/test/AArch64/symbol-hashes.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// This test checks that we don't try to use symbols outside of section when
2+
// generating symbol hashes
3+
4+
RUN: yaml2obj %p/Inputs/symbol-hashes.yaml -o %t.exe
5+
RUN: llvm-bolt %t.exe -force-data-relocations -o %t.exe.bolt
6+

clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,19 +235,19 @@ void UseEqualsDefaultCheck::registerMatchers(MatchFinder *Finder) {
235235

236236
// Destructor.
237237
Finder->addMatcher(
238-
cxxDestructorDecl(unless(hasParent(IsUnionLikeClass)), isDefinition())
238+
cxxDestructorDecl(isDefinition(), unless(ofClass(IsUnionLikeClass)))
239239
.bind(SpecialFunction),
240240
this);
241+
// Constructor.
241242
Finder->addMatcher(
242243
cxxConstructorDecl(
243-
unless(
244-
hasParent(decl(anyOf(IsUnionLikeClass, functionTemplateDecl())))),
245-
isDefinition(),
244+
isDefinition(), unless(ofClass(IsUnionLikeClass)),
245+
unless(hasParent(functionTemplateDecl())),
246246
anyOf(
247247
// Default constructor.
248-
allOf(unless(hasAnyConstructorInitializer(isWritten())),
249-
unless(isVariadic()), parameterCountIs(0),
250-
IsPublicOrOutOfLineUntilCPP20),
248+
allOf(parameterCountIs(0),
249+
unless(hasAnyConstructorInitializer(isWritten())),
250+
unless(isVariadic()), IsPublicOrOutOfLineUntilCPP20),
251251
// Copy constructor.
252252
allOf(isCopyConstructor(),
253253
// Discard constructors that can be used as a copy
@@ -258,9 +258,9 @@ void UseEqualsDefaultCheck::registerMatchers(MatchFinder *Finder) {
258258
this);
259259
// Copy-assignment operator.
260260
Finder->addMatcher(
261-
cxxMethodDecl(unless(hasParent(
262-
decl(anyOf(IsUnionLikeClass, functionTemplateDecl())))),
263-
isDefinition(), isCopyAssignmentOperator(),
261+
cxxMethodDecl(isDefinition(), isCopyAssignmentOperator(),
262+
unless(ofClass(IsUnionLikeClass)),
263+
unless(hasParent(functionTemplateDecl())),
264264
// isCopyAssignmentOperator() allows the parameter to be
265265
// passed by value, and in this case it cannot be
266266
// defaulted.
@@ -299,6 +299,12 @@ void UseEqualsDefaultCheck::check(const MatchFinder::MatchResult &Result) {
299299
if (!SpecialFunctionDecl->isCopyAssignmentOperator() && !Body->body_empty())
300300
return;
301301

302+
// If body contain any preprocesor derictives, don't warn.
303+
if (IgnoreMacros && utils::lexer::rangeContainsExpansionsOrDirectives(
304+
Body->getSourceRange(), *Result.SourceManager,
305+
Result.Context->getLangOpts()))
306+
return;
307+
302308
// If there are comments inside the body, don't do the change.
303309
bool ApplyFix = SpecialFunctionDecl->isCopyAssignmentOperator() ||
304310
bodyEmpty(Result.Context, Body);
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
//===--- AvoidUnconditionalPreprocessorIfCheck.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 "AvoidUnconditionalPreprocessorIfCheck.h"
10+
#include "clang/AST/ASTContext.h"
11+
#include "clang/Lex/PPCallbacks.h"
12+
#include "clang/Lex/Preprocessor.h"
13+
14+
using namespace clang::ast_matchers;
15+
16+
namespace clang::tidy::readability {
17+
18+
namespace {
19+
struct AvoidUnconditionalPreprocessorIfPPCallbacks : public PPCallbacks {
20+
21+
explicit AvoidUnconditionalPreprocessorIfPPCallbacks(ClangTidyCheck &Check,
22+
Preprocessor &PP)
23+
: Check(Check), PP(PP) {}
24+
25+
void If(SourceLocation Loc, SourceRange ConditionRange,
26+
ConditionValueKind ConditionValue) override {
27+
if (ConditionValue == CVK_NotEvaluated)
28+
return;
29+
SourceManager &SM = PP.getSourceManager();
30+
if (!isImmutable(SM, PP.getLangOpts(), ConditionRange))
31+
return;
32+
33+
if (ConditionValue == CVK_True)
34+
Check.diag(Loc, "preprocessor condition is always 'true', consider "
35+
"removing condition but leaving its contents");
36+
else
37+
Check.diag(Loc, "preprocessor condition is always 'false', consider "
38+
"removing both the condition and its contents");
39+
}
40+
41+
bool isImmutable(SourceManager &SM, const LangOptions &LangOpts,
42+
SourceRange ConditionRange) {
43+
SourceLocation Loc = ConditionRange.getBegin();
44+
if (Loc.isMacroID())
45+
return false;
46+
47+
Token Tok;
48+
if (Lexer::getRawToken(Loc, Tok, SM, LangOpts, true)) {
49+
std::optional<Token> TokOpt = Lexer::findNextToken(Loc, SM, LangOpts);
50+
if (!TokOpt || TokOpt->getLocation().isMacroID())
51+
return false;
52+
Tok = *TokOpt;
53+
}
54+
55+
while (Tok.getLocation() <= ConditionRange.getEnd()) {
56+
if (!isImmutableToken(Tok))
57+
return false;
58+
59+
std::optional<Token> TokOpt =
60+
Lexer::findNextToken(Tok.getLocation(), SM, LangOpts);
61+
if (!TokOpt || TokOpt->getLocation().isMacroID())
62+
return false;
63+
Tok = *TokOpt;
64+
}
65+
66+
return true;
67+
}
68+
69+
bool isImmutableToken(const Token &Tok) {
70+
switch (Tok.getKind()) {
71+
case tok::eod:
72+
case tok::eof:
73+
case tok::numeric_constant:
74+
case tok::char_constant:
75+
case tok::wide_char_constant:
76+
case tok::utf8_char_constant:
77+
case tok::utf16_char_constant:
78+
case tok::utf32_char_constant:
79+
case tok::string_literal:
80+
case tok::wide_string_literal:
81+
case tok::comment:
82+
return true;
83+
case tok::raw_identifier:
84+
return (Tok.getRawIdentifier() == "true" ||
85+
Tok.getRawIdentifier() == "false");
86+
default:
87+
return Tok.getKind() >= tok::l_square && Tok.getKind() <= tok::caretcaret;
88+
}
89+
}
90+
91+
ClangTidyCheck &Check;
92+
Preprocessor &PP;
93+
};
94+
95+
} // namespace
96+
97+
void AvoidUnconditionalPreprocessorIfCheck::registerPPCallbacks(
98+
const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
99+
PP->addPPCallbacks(
100+
std::make_unique<AvoidUnconditionalPreprocessorIfPPCallbacks>(*this,
101+
*PP));
102+
}
103+
104+
} // namespace clang::tidy::readability
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//===--- AvoidUnconditionalPreprocessorIfCheck.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_READABILITY_AVOIDUNCONDITIONALPREPROCESSORIFCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOIDUNCONDITIONALPREPROCESSORIFCHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang::tidy::readability {
15+
16+
/// Finds code blocks that are constantly enabled or disabled in preprocessor
17+
/// directives by analyzing `#if` conditions, such as `#if 0` and `#if 1`, etc.
18+
///
19+
/// For the user-facing documentation see:
20+
/// http://clang.llvm.org/extra/clang-tidy/checks/readability/avoid-unconditional-preprocessor-if.html
21+
class AvoidUnconditionalPreprocessorIfCheck : public ClangTidyCheck {
22+
public:
23+
AvoidUnconditionalPreprocessorIfCheck(StringRef Name,
24+
ClangTidyContext *Context)
25+
: ClangTidyCheck(Name, Context) {}
26+
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
27+
Preprocessor *ModuleExpanderPP) override;
28+
};
29+
30+
} // namespace clang::tidy::readability
31+
32+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOIDUNCONDITIONALPREPROCESSORIFCHECK_H

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set(LLVM_LINK_COMPONENTS
55

66
add_clang_library(clangTidyReadabilityModule
77
AvoidConstParamsInDecls.cpp
8+
AvoidUnconditionalPreprocessorIfCheck.cpp
89
BracesAroundStatementsCheck.cpp
910
ConstReturnTypeCheck.cpp
1011
ContainerContainsCheck.cpp

clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ MagicNumbersCheck::MagicNumbersCheck(StringRef Name, ClangTidyContext *Context)
8181
IgnorePowersOf2IntegerValues(
8282
Options.get("IgnorePowersOf2IntegerValues", false)),
8383
IgnoreTypeAliases(Options.get("IgnoreTypeAliases", false)),
84+
IgnoreUserDefinedLiterals(
85+
Options.get("IgnoreUserDefinedLiterals", false)),
8486
RawIgnoredIntegerValues(
8587
Options.get("IgnoredIntegerValues", DefaultIgnoredIntegerValues)),
8688
RawIgnoredFloatingPointValues(Options.get(
@@ -130,6 +132,7 @@ void MagicNumbersCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
130132
Options.store(Opts, "IgnorePowersOf2IntegerValues",
131133
IgnorePowersOf2IntegerValues);
132134
Options.store(Opts, "IgnoreTypeAliases", IgnoreTypeAliases);
135+
Options.store(Opts, "IgnoreUserDefinedLiterals", IgnoreUserDefinedLiterals);
133136
Options.store(Opts, "IgnoredIntegerValues", RawIgnoredIntegerValues);
134137
Options.store(Opts, "IgnoredFloatingPointValues",
135138
RawIgnoredFloatingPointValues);
@@ -243,5 +246,14 @@ bool MagicNumbersCheck::isBitFieldWidth(
243246
});
244247
}
245248

249+
bool MagicNumbersCheck::isUserDefinedLiteral(
250+
const clang::ast_matchers::MatchFinder::MatchResult &Result,
251+
const clang::Expr &Literal) const {
252+
DynTypedNodeList Parents = Result.Context->getParents(Literal);
253+
if (Parents.empty())
254+
return false;
255+
return Parents[0].get<UserDefinedLiteral>() != nullptr;
256+
}
257+
246258
} // namespace tidy::readability
247259
} // namespace clang

clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class MagicNumbersCheck : public ClangTidyCheck {
4949
bool isBitFieldWidth(const clang::ast_matchers::MatchFinder::MatchResult &Result,
5050
const IntegerLiteral &Literal) const;
5151

52+
bool isUserDefinedLiteral(
53+
const clang::ast_matchers::MatchFinder::MatchResult &Result,
54+
const clang::Expr &Literal) const;
55+
5256
template <typename L>
5357
void checkBoundMatch(const ast_matchers::MatchFinder::MatchResult &Result,
5458
const char *BoundName) {
@@ -72,6 +76,10 @@ class MagicNumbersCheck : public ClangTidyCheck {
7276
if (isBitFieldWidth(Result, *MatchedLiteral))
7377
return;
7478

79+
if (IgnoreUserDefinedLiterals &&
80+
isUserDefinedLiteral(Result, *MatchedLiteral))
81+
return;
82+
7583
const StringRef LiteralSourceText = Lexer::getSourceText(
7684
CharSourceRange::getTokenRange(MatchedLiteral->getSourceRange()),
7785
*Result.SourceManager, getLangOpts());
@@ -85,6 +93,7 @@ class MagicNumbersCheck : public ClangTidyCheck {
8593
const bool IgnoreBitFieldsWidths;
8694
const bool IgnorePowersOf2IntegerValues;
8795
const bool IgnoreTypeAliases;
96+
const bool IgnoreUserDefinedLiterals;
8897
const StringRef RawIgnoredIntegerValues;
8998
const StringRef RawIgnoredFloatingPointValues;
9099

0 commit comments

Comments
 (0)