Skip to content

Commit 84ee3fa

Browse files
Merge branch 'llvm:main' into gh-101657
2 parents 57cb805 + 17b4be8 commit 84ee3fa

File tree

103 files changed

+4314
-3311
lines changed

Some content is hidden

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

103 files changed

+4314
-3311
lines changed

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,18 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
547547
return false;
548548
}
549549

550+
bool isBRA(const MCInst &Inst) const {
551+
switch (Inst.getOpcode()) {
552+
case AArch64::BRAA:
553+
case AArch64::BRAB:
554+
case AArch64::BRAAZ:
555+
case AArch64::BRABZ:
556+
return true;
557+
default:
558+
return false;
559+
}
560+
}
561+
550562
bool mayLoad(const MCInst &Inst) const override {
551563
return isLDRB(Inst) || isLDRH(Inst) || isLDRW(Inst) || isLDRX(Inst) ||
552564
isLDRQ(Inst) || isLDRD(Inst) || isLDRS(Inst);
@@ -941,6 +953,11 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
941953
DenseMap<const MCInst *, SmallVector<MCInst *, 4>> &UDChain,
942954
const MCExpr *&JumpTable, int64_t &Offset, int64_t &ScaleValue,
943955
MCInst *&PCRelBase) const {
956+
// The only kind of indirect branches we match is jump table, thus ignore
957+
// authenticating branch instructions early.
958+
if (isBRA(Inst))
959+
return false;
960+
944961
// Expect AArch64 BR
945962
assert(Inst.getOpcode() == AArch64::BR && "Unexpected opcode");
946963

bolt/test/AArch64/test-indirect-branch.s

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// REQUIRES: system-linux, asserts
77

8-
// RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
8+
// RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown -mattr=+pauth %s -o %t.o
99
// RUN: %clang %cflags --target=aarch64-unknown-linux %t.o -o %t.exe -Wl,-q
1010
// RUN: llvm-bolt %t.exe -o %t.bolt --print-cfg --strict --debug-only=mcplus \
1111
// RUN: -v=1 2>&1 | FileCheck %s
@@ -73,6 +73,27 @@ test2_0:
7373
test2_1:
7474
ret
7575

76+
// Make sure BOLT does not crash trying to disassemble BRA* instructions.
77+
.globl test_braa
78+
.type test_braa, %function
79+
test_braa:
80+
braa x0, x1
81+
82+
.globl test_brab
83+
.type test_brab, %function
84+
test_brab:
85+
brab x0, x1
86+
87+
.globl test_braaz
88+
.type test_braaz, %function
89+
test_braaz:
90+
braaz x0
91+
92+
.globl test_brabz
93+
.type test_brabz, %function
94+
test_brabz:
95+
brabz x0
96+
7697
.section .rodata,"a",@progbits
7798
datatable:
7899
.word test1_0-datatable

clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ def main():
259259
action="store_true",
260260
help="Only check files in the compilation database",
261261
)
262+
parser.add_argument(
263+
"-warnings-as-errors",
264+
help="Upgrades clang-tidy warnings to errors. Same format as '-checks'.",
265+
default="",
266+
)
262267

263268
clang_tidy_args = []
264269
argv = sys.argv[1:]
@@ -374,6 +379,8 @@ def main():
374379
common_clang_tidy_args.append("-extra-arg-before=%s" % arg)
375380
for plugin in args.plugins:
376381
common_clang_tidy_args.append("-load=%s" % plugin)
382+
if args.warnings_as_errors:
383+
common_clang_tidy_args.append("-warnings-as-errors=" + args.warnings_as_errors)
377384

378385
for name in lines_by_file:
379386
line_filter_json = json.dumps(

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ Improvements to clang-tidy
9797
Note: this may lead to false negatives; downstream users may need to adjust
9898
their checks to preserve existing behavior.
9999

100+
- Improved :program:`clang-tidy-diff.py` script. Add the `-warnings-as-errors`
101+
argument to treat warnings as errors.
102+
100103
New checks
101104
^^^^^^^^^^
102105

clang/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h"
1818
#include "clang/StaticAnalyzer/Core/Checker.h"
1919
#include <string>
20+
#include <variant>
2021

2122
namespace clang {
2223

@@ -26,36 +27,53 @@ class BugReporter;
2627

2728
class BugType {
2829
private:
29-
const CheckerNameRef CheckerName;
30+
struct CheckerPartRef {
31+
const CheckerBase *Checker;
32+
CheckerPartIdx Idx;
33+
};
34+
using CheckerNameInfo = std::variant<CheckerNameRef, CheckerPartRef>;
35+
36+
const CheckerNameInfo CheckerName;
3037
const std::string Description;
3138
const std::string Category;
32-
const CheckerBase *Checker;
3339
bool SuppressOnSink;
3440

3541
virtual void anchor();
3642

3743
public:
44+
// Straightforward constructor where the checker name is specified directly.
45+
// TODO: As far as I know all applications of this constructor involve ugly
46+
// hacks that could be avoided by switching to a different constructor.
47+
// When those are all eliminated, this constructor should be removed to
48+
// eliminate the `variant` and simplify this class.
3849
BugType(CheckerNameRef CheckerName, StringRef Desc,
3950
StringRef Cat = categories::LogicError, bool SuppressOnSink = false)
4051
: CheckerName(CheckerName), Description(Desc), Category(Cat),
41-
Checker(nullptr), SuppressOnSink(SuppressOnSink) {}
52+
SuppressOnSink(SuppressOnSink) {}
53+
// Constructor that can be called from the constructor of a checker object.
54+
// At that point the checker name is not yet available, but we can save a
55+
// pointer to the checker and later use that to query the name.
4256
BugType(const CheckerBase *Checker, StringRef Desc,
4357
StringRef Cat = categories::LogicError, bool SuppressOnSink = false)
44-
: CheckerName(), Description(Desc), Category(Cat), Checker(Checker),
45-
SuppressOnSink(SuppressOnSink) {}
58+
: CheckerName(CheckerPartRef{Checker, DefaultPart}), Description(Desc),
59+
Category(Cat), SuppressOnSink(SuppressOnSink) {}
60+
// Constructor that can be called from the constructor of a checker object
61+
// when it has multiple parts with separate names. We save the name and the
62+
// part index to be able to query the name of that part later.
63+
BugType(const CheckerBase *Checker, CheckerPartIdx Idx, StringRef Desc,
64+
StringRef Cat = categories::LogicError, bool SuppressOnSink = false)
65+
: CheckerName(CheckerPartRef{Checker, Idx}), Description(Desc),
66+
Category(Cat), SuppressOnSink(SuppressOnSink) {}
4667
virtual ~BugType() = default;
4768

4869
StringRef getDescription() const { return Description; }
4970
StringRef getCategory() const { return Category; }
5071
StringRef getCheckerName() const {
51-
// FIXME: This is a workaround to ensure that the correct checker name is
52-
// used. The checker names are set after the constructors are run.
53-
// In case the BugType object is initialized in the checker's ctor
54-
// the CheckerName field will be empty. To circumvent this problem we use
55-
// CheckerBase whenever it is possible.
56-
StringRef Ret = Checker ? Checker->getName() : CheckerName;
57-
assert(!Ret.empty() && "Checker name is not set properly.");
58-
return Ret;
72+
if (const auto *CNR = std::get_if<CheckerNameRef>(&CheckerName))
73+
return *CNR;
74+
75+
auto [Checker, Idx] = std::get<CheckerPartRef>(CheckerName);
76+
return Checker->getName(Idx);
5977
}
6078

6179
/// isSuppressOnSink - Returns true if bug reports associated with this bug

clang/include/clang/StaticAnalyzer/Core/Checker.h

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,16 +485,60 @@ class Call {
485485
} // end eval namespace
486486

487487
class CheckerBase : public ProgramPointTag {
488-
CheckerNameRef Name;
488+
/// A single checker class (i.e. a subclass of `CheckerBase`) can implement
489+
/// multiple user-facing checkers that have separate names and can be enabled
490+
/// separately, but are backed by the same singleton checker object.
491+
SmallVector<std::optional<CheckerNameRef>, 1> RegisteredNames;
492+
489493
friend class ::clang::ento::CheckerManager;
490494

491495
public:
492-
StringRef getTagDescription() const override;
493-
CheckerNameRef getName() const;
496+
CheckerNameRef getName(CheckerPartIdx Idx = DefaultPart) const {
497+
assert(Idx < RegisteredNames.size() && "Checker part index is too large!");
498+
std::optional<CheckerNameRef> Name = RegisteredNames[Idx];
499+
assert(Name && "Requested checker part is not registered!");
500+
return *Name;
501+
}
502+
503+
bool isPartEnabled(CheckerPartIdx Idx) const {
504+
return Idx < RegisteredNames.size() && RegisteredNames[Idx].has_value();
505+
}
506+
507+
void registerCheckerPart(CheckerPartIdx Idx, CheckerNameRef Name) {
508+
// Paranoia: notice if e.g. UINT_MAX is passed as a checker part index.
509+
assert(Idx < 256 && "Checker part identifiers should be small integers.");
510+
511+
if (Idx >= RegisteredNames.size())
512+
RegisteredNames.resize(Idx + 1, std::nullopt);
513+
514+
assert(!RegisteredNames[Idx] && "Repeated registration of checker a part!");
515+
RegisteredNames[Idx] = Name;
516+
}
517+
518+
StringRef getTagDescription() const override {
519+
// This method inherited from `ProgramPointTag` has two unrelated roles:
520+
// (1) The analyzer option handling logic uses this method to query the
521+
// name of a checker.
522+
// (2) When the `ExplodedGraph` is dumped in DOT format for debugging,
523+
// this is called to attach a description to the nodes. (This happens
524+
// for all subclasses of `ProgramPointTag`, not just checkers.)
525+
// FIXME: Application (1) should be aware of multiple parts within the same
526+
// checker class instance, so it should directly use `getName` instead of
527+
// this inherited interface which cannot support a `CheckerPartIdx`.
528+
// FIXME: Ideally application (2) should return a string that describes the
529+
// whole checker class, not just one of it parts. However, this is only for
530+
// debugging, so returning the name of one part is probably good enough.
531+
for (const auto &OptName : RegisteredNames)
532+
if (OptName)
533+
return *OptName;
534+
535+
return "Unregistered checker";
536+
}
494537

495-
/// See CheckerManager::runCheckersForPrintState.
538+
/// Debug state dump callback, see CheckerManager::runCheckersForPrintState.
539+
/// Default implementation does nothing.
496540
virtual void printState(raw_ostream &Out, ProgramStateRef State,
497-
const char *NL, const char *Sep) const { }
541+
const char *NL, const char *Sep) const;
498542
};
499543

500544
/// Dump checker name to stream.

clang/include/clang/StaticAnalyzer/Core/CheckerManager.h

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ class CheckerNameRef {
116116
operator StringRef() const { return Name; }
117117
};
118118

119+
/// A single checker class (and its singleton instance) can act as the
120+
/// implementation of several (user-facing or modeling) checker parts that
121+
/// have shared state and logic, but have their own names and can be enabled or
122+
/// disabled separately.
123+
/// Each checker class that implement multiple parts introduces its own enum
124+
/// type to assign small numerical indices (0, 1, 2 ...) to their parts. The
125+
/// type alias 'CheckerPartIdx' is conceptually the union of these enum types.
126+
using CheckerPartIdx = unsigned;
127+
128+
/// If a checker doesn't have multiple parts, then its single part is
129+
/// represented by this index.
130+
constexpr inline CheckerPartIdx DefaultPart = 0;
131+
119132
enum class ObjCMessageVisitKind {
120133
Pre,
121134
Post,
@@ -190,23 +203,38 @@ class CheckerManager {
190203
// Checker registration.
191204
//===--------------------------------------------------------------------===//
192205

193-
/// Used to register checkers.
194-
/// All arguments are automatically passed through to the checker
195-
/// constructor.
206+
/// Construct the singleton instance of a checker, register it for the
207+
/// supported callbacks and record its name with `registerCheckerPart()`.
208+
/// Arguments passed to this function are forwarded to the constructor of the
209+
/// checker.
210+
///
211+
/// If `CHECKER` has multiple parts, then the constructor call and the
212+
/// callback registration only happen within the first `registerChecker()`
213+
/// call; while the subsequent calls only enable additional parts of the
214+
/// existing checker object (while registering their names).
196215
///
197216
/// \returns a pointer to the checker object.
198-
template <typename CHECKER, typename... AT>
199-
CHECKER *registerChecker(AT &&... Args) {
217+
template <typename CHECKER, CheckerPartIdx Idx = DefaultPart, typename... AT>
218+
CHECKER *registerChecker(AT &&...Args) {
219+
// This assert could be removed but then we need to make sure that calls
220+
// registering different parts of the same checker pass the same arguments.
221+
static_assert(
222+
Idx == DefaultPart || !sizeof...(AT),
223+
"Argument forwarding isn't supported with multi-part checkers!");
224+
200225
CheckerTag Tag = getTag<CHECKER>();
201-
std::unique_ptr<CheckerBase> &Ref = CheckerTags[Tag];
202-
assert(!Ref && "Checker already registered, use getChecker!");
203226

204-
std::unique_ptr<CHECKER> Checker =
205-
std::make_unique<CHECKER>(std::forward<AT>(Args)...);
206-
Checker->Name = CurrentCheckerName;
207-
CHECKER::_register(Checker.get(), *this);
208-
Ref = std::move(Checker);
209-
return static_cast<CHECKER *>(Ref.get());
227+
std::unique_ptr<CheckerBase> &Ref = CheckerTags[Tag];
228+
if (!Ref) {
229+
std::unique_ptr<CHECKER> Checker =
230+
std::make_unique<CHECKER>(std::forward<AT>(Args)...);
231+
CHECKER::_register(Checker.get(), *this);
232+
Ref = std::move(Checker);
233+
}
234+
235+
CHECKER *Result = static_cast<CHECKER *>(Ref.get());
236+
Result->registerCheckerPart(Idx, CurrentCheckerName);
237+
return Result;
210238
}
211239

212240
template <typename CHECKER>

clang/include/clang/Support/Compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
#define CLANG_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
5555
#define CLANG_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
5656
#define CLANG_EXPORT_TEMPLATE
57-
#elif defined(__MACH__) || defined(__WASM__)
57+
#elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__)
5858
#define CLANG_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
5959
#define CLANG_TEMPLATE_ABI
6060
#define CLANG_EXPORT_TEMPLATE

clang/lib/CodeGen/CGException.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2145,7 +2145,7 @@ llvm::Value *CodeGenFunction::EmitSEHExceptionInfo() {
21452145
// Sema should diagnose calling this builtin outside of a filter context, but
21462146
// don't crash if we screw up.
21472147
if (!SEHInfo)
2148-
return llvm::UndefValue::get(Int8PtrTy);
2148+
return llvm::PoisonValue::get(Int8PtrTy);
21492149
assert(SEHInfo->getType() == Int8PtrTy);
21502150
return SEHInfo;
21512151
}

clang/lib/Sema/SemaAccess.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,8 +1518,8 @@ void Sema::HandleDelayedAccessCheck(DelayedDiagnostic &DD, Decl *D) {
15181518
} else if (FunctionDecl *FN = dyn_cast<FunctionDecl>(D)) {
15191519
DC = FN;
15201520
} else if (TemplateDecl *TD = dyn_cast<TemplateDecl>(D)) {
1521-
if (isa<DeclContext>(TD->getTemplatedDecl()))
1522-
DC = cast<DeclContext>(TD->getTemplatedDecl());
1521+
if (auto *D = dyn_cast_if_present<DeclContext>(TD->getTemplatedDecl()))
1522+
DC = D;
15231523
} else if (auto *RD = dyn_cast<RequiresExprBodyDecl>(D)) {
15241524
DC = RD;
15251525
}

0 commit comments

Comments
 (0)