Skip to content

Commit 4fe5a3c

Browse files
committed
Merge from 'main' to 'sycl-web' (118 commits)
CONFLICT (content): Merge conflict in clang/include/clang/Basic/DiagnosticGroups.td
2 parents 1610f63 + efefee2 commit 4fe5a3c

File tree

647 files changed

+6630
-3013
lines changed

Some content is hidden

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

647 files changed

+6630
-3013
lines changed

.github/workflows/issue-write.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ jobs:
1818
permissions:
1919
pull-requests: write
2020
if: >
21-
github.event.workflow_run.event == 'pull_request'
21+
github.event.workflow_run.event == 'pull_request' &&
22+
(
23+
github.event.workflow_run.conclusion == 'success' ||
24+
github.event.workflow_run.conclusion == 'failure'
25+
)
2226
steps:
2327
- name: 'Download artifact'
2428
uses: actions/download-artifact@6b208ae046db98c579e8a3aa621ab581ff575935 # v4.1.1

bolt/include/bolt/Rewrite/DWARFRewriter.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "llvm/ADT/StringRef.h"
1717
#include "llvm/CodeGen/DIE.h"
1818
#include "llvm/DWP/DWP.h"
19-
#include "llvm/MC/MCAsmLayout.h"
2019
#include "llvm/MC/MCContext.h"
2120
#include "llvm/Support/ToolOutputFile.h"
2221
#include <cstdint>
@@ -183,7 +182,7 @@ class DWARFRewriter {
183182
void updateDebugInfo();
184183

185184
/// Update stmt_list for CUs based on the new .debug_line \p Layout.
186-
void updateLineTableOffsets(const MCAsmLayout &Layout);
185+
void updateLineTableOffsets(const MCAssembler &Asm);
187186

188187
uint64_t getDwoRangesBase(uint64_t DWOId) { return DwoRangesBase[DWOId]; }
189188

bolt/lib/Core/BinaryContext.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
2121
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
2222
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
23-
#include "llvm/MC/MCAsmLayout.h"
2423
#include "llvm/MC/MCAssembler.h"
2524
#include "llvm/MC/MCContext.h"
2625
#include "llvm/MC/MCDisassembler/MCDisassembler.h"
@@ -2416,20 +2415,19 @@ BinaryContext::calculateEmittedSize(BinaryFunction &BF, bool FixBranches) {
24162415

24172416
MCAssembler &Assembler =
24182417
static_cast<MCObjectStreamer *>(Streamer.get())->getAssembler();
2419-
MCAsmLayout Layout(Assembler);
2420-
Assembler.layout(Layout);
2418+
Assembler.layout();
24212419

24222420
// Obtain fragment sizes.
24232421
std::vector<uint64_t> FragmentSizes;
24242422
// Main fragment size.
2425-
const uint64_t HotSize =
2426-
Layout.getSymbolOffset(*EndLabel) - Layout.getSymbolOffset(*StartLabel);
2423+
const uint64_t HotSize = Assembler.getSymbolOffset(*EndLabel) -
2424+
Assembler.getSymbolOffset(*StartLabel);
24272425
FragmentSizes.push_back(HotSize);
24282426
// Split fragment sizes.
24292427
uint64_t ColdSize = 0;
24302428
for (const auto &Labels : SplitLabels) {
2431-
uint64_t Size = Layout.getSymbolOffset(*Labels.second) -
2432-
Layout.getSymbolOffset(*Labels.first);
2429+
uint64_t Size = Assembler.getSymbolOffset(*Labels.second) -
2430+
Assembler.getSymbolOffset(*Labels.first);
24332431
FragmentSizes.push_back(Size);
24342432
ColdSize += Size;
24352433
}
@@ -2439,7 +2437,8 @@ BinaryContext::calculateEmittedSize(BinaryFunction &BF, bool FixBranches) {
24392437
for (FunctionFragment &FF : BF.getLayout().fragments()) {
24402438
BinaryBasicBlock *PrevBB = nullptr;
24412439
for (BinaryBasicBlock *BB : FF) {
2442-
const uint64_t BBStartOffset = Layout.getSymbolOffset(*(BB->getLabel()));
2440+
const uint64_t BBStartOffset =
2441+
Assembler.getSymbolOffset(*(BB->getLabel()));
24432442
BB->setOutputStartAddress(BBStartOffset);
24442443
if (PrevBB)
24452444
PrevBB->setOutputEndAddress(BBStartOffset);

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
3030
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
3131
#include "llvm/MC/MCAsmBackend.h"
32-
#include "llvm/MC/MCAsmLayout.h"
32+
#include "llvm/MC/MCAssembler.h"
3333
#include "llvm/MC/MCObjectWriter.h"
3434
#include "llvm/MC/MCStreamer.h"
3535
#include "llvm/Object/ObjectFile.h"
@@ -1351,7 +1351,7 @@ void DWARFRewriter::updateDWARFObjectAddressRanges(
13511351
}
13521352
}
13531353

1354-
void DWARFRewriter::updateLineTableOffsets(const MCAsmLayout &Layout) {
1354+
void DWARFRewriter::updateLineTableOffsets(const MCAssembler &Asm) {
13551355
ErrorOr<BinarySection &> DbgInfoSection =
13561356
BC.getUniqueSectionByName(".debug_info");
13571357
ErrorOr<BinarySection &> TypeInfoSection =
@@ -1392,7 +1392,8 @@ void DWARFRewriter::updateLineTableOffsets(const MCAsmLayout &Layout) {
13921392
if (!StmtOffset)
13931393
continue;
13941394

1395-
const uint64_t LineTableOffset = Layout.getSymbolOffset(*Label);
1395+
const uint64_t LineTableOffset =
1396+
Asm.getSymbolOffset(*Label);
13961397
DebugLineOffsetMap[*StmtOffset] = LineTableOffset;
13971398
assert(DbgInfoSection && ".debug_info section must exist");
13981399
LineTablePatchMap[CU.get()] = LineTableOffset;

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#include "llvm/DebugInfo/DWARF/DWARFDebugFrame.h"
4141
#include "llvm/MC/MCAsmBackend.h"
4242
#include "llvm/MC/MCAsmInfo.h"
43-
#include "llvm/MC/MCAsmLayout.h"
4443
#include "llvm/MC/MCDisassembler/MCDisassembler.h"
4544
#include "llvm/MC/MCObjectStreamer.h"
4645
#include "llvm/MC/MCStreamer.h"
@@ -3508,9 +3507,8 @@ void RewriteInstance::emitAndLink() {
35083507
updateOutputValues(*Linker);
35093508

35103509
if (opts::UpdateDebugSections) {
3511-
MCAsmLayout FinalLayout(
3512-
static_cast<MCObjectStreamer *>(Streamer.get())->getAssembler());
3513-
DebugInfoRewriter->updateLineTableOffsets(FinalLayout);
3510+
DebugInfoRewriter->updateLineTableOffsets(
3511+
static_cast<MCObjectStreamer &>(*Streamer).getAssembler());
35143512
}
35153513

35163514
if (RuntimeLibrary *RtLibrary = BC->getRuntimeLibrary())

bolt/test/X86/reader-stale-yaml-std.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# UNSUPPORTED: true
12
## This script checks that YamlProfileReader in llvm-bolt is reading data
23
## correctly and stale data is corrected by profile inference.
34

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
296296
} else if (const auto *E =
297297
Result.Nodes.getNodeAs<Expr>("sizeof-integer-call")) {
298298
diag(E->getBeginLoc(), "suspicious usage of 'sizeof()' on an expression "
299-
"that results in an integer")
299+
"of integer type")
300300
<< E->getSourceRange();
301301
} else if (const auto *E = Result.Nodes.getNodeAs<Expr>("sizeof-this")) {
302302
diag(E->getBeginLoc(),
@@ -314,7 +314,7 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
314314
<< E->getSourceRange();
315315
} else {
316316
diag(E->getBeginLoc(), "suspicious usage of 'sizeof()' on an expression "
317-
"that results in a pointer")
317+
"of pointer type")
318318
<< E->getSourceRange();
319319
}
320320
} else if (const auto *E = Result.Nodes.getNodeAs<BinaryOperator>(
@@ -348,25 +348,28 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
348348
} else if (ElementSize > CharUnits::Zero() &&
349349
DenominatorSize > CharUnits::Zero() &&
350350
ElementSize != DenominatorSize) {
351-
diag(E->getOperatorLoc(), "suspicious usage of 'sizeof(...)/sizeof(...)';"
352-
" numerator is not a multiple of denominator")
351+
// FIXME: Apparently there are no testcases that cover this branch!
352+
diag(E->getOperatorLoc(),
353+
"suspicious usage of 'sizeof(array)/sizeof(...)';"
354+
" denominator differs from the size of array elements")
353355
<< E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
354356
} else if (NumTy && DenomTy && NumTy == DenomTy) {
355-
// FIXME: This message is wrong, it should not refer to sizeof "pointer"
356-
// usage (and by the way, it would be to clarify all the messages).
357357
diag(E->getOperatorLoc(),
358-
"suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'")
358+
"suspicious usage of 'sizeof(...)/sizeof(...)'; both expressions "
359+
"have the same type")
359360
<< E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
360361
} else if (!WarnOnSizeOfPointer) {
361362
// When 'WarnOnSizeOfPointer' is enabled, these messages become redundant:
362363
if (PointedTy && DenomTy && PointedTy == DenomTy) {
363364
diag(E->getOperatorLoc(),
364-
"suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)'")
365+
"suspicious usage of 'sizeof(...)/sizeof(...)'; size of pointer "
366+
"is divided by size of pointed type")
365367
<< E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
366368
} else if (NumTy && DenomTy && NumTy->isPointerType() &&
367369
DenomTy->isPointerType()) {
368370
diag(E->getOperatorLoc(),
369-
"suspicious usage of sizeof pointer 'sizeof(P*)/sizeof(Q*)'")
371+
"suspicious usage of 'sizeof(...)/sizeof(...)'; both expressions "
372+
"have pointer types")
370373
<< E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
371374
}
372375
}

clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,30 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "AvoidNonConstGlobalVariablesCheck.h"
10-
#include "clang/AST/ASTContext.h"
1110
#include "clang/ASTMatchers/ASTMatchFinder.h"
1211
#include "clang/ASTMatchers/ASTMatchers.h"
1312

1413
using namespace clang::ast_matchers;
1514

1615
namespace clang::tidy::cppcoreguidelines {
1716

17+
AvoidNonConstGlobalVariablesCheck::AvoidNonConstGlobalVariablesCheck(
18+
StringRef Name, ClangTidyContext *Context)
19+
: ClangTidyCheck(Name, Context),
20+
AllowInternalLinkage(Options.get("AllowInternalLinkage", false)) {}
21+
1822
void AvoidNonConstGlobalVariablesCheck::registerMatchers(MatchFinder *Finder) {
23+
auto NamespaceMatcher = AllowInternalLinkage
24+
? namespaceDecl(unless(isAnonymous()))
25+
: namespaceDecl();
1926
auto GlobalContext =
2027
varDecl(hasGlobalStorage(),
21-
hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl())));
28+
hasDeclContext(anyOf(NamespaceMatcher, translationUnitDecl())));
2229

2330
auto GlobalVariable = varDecl(
2431
GlobalContext,
32+
AllowInternalLinkage ? varDecl(unless(isStaticStorageClass()))
33+
: varDecl(),
2534
unless(anyOf(
2635
isConstexpr(), hasType(isConstQualified()),
2736
hasType(referenceType())))); // References can't be changed, only the
@@ -43,7 +52,6 @@ void AvoidNonConstGlobalVariablesCheck::registerMatchers(MatchFinder *Finder) {
4352

4453
void AvoidNonConstGlobalVariablesCheck::check(
4554
const MatchFinder::MatchResult &Result) {
46-
4755
if (const auto *Variable =
4856
Result.Nodes.getNodeAs<VarDecl>("non-const_variable")) {
4957
diag(Variable->getLocation(), "variable %0 is non-const and globally "
@@ -63,4 +71,9 @@ void AvoidNonConstGlobalVariablesCheck::check(
6371
}
6472
}
6573

74+
void AvoidNonConstGlobalVariablesCheck::storeOptions(
75+
ClangTidyOptions::OptionMap &Opts) {
76+
Options.store(Opts, "AllowInternalLinkage", AllowInternalLinkage);
77+
}
78+
6679
} // namespace clang::tidy::cppcoreguidelines

clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ namespace clang::tidy::cppcoreguidelines {
2020
/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables.html
2121
class AvoidNonConstGlobalVariablesCheck : public ClangTidyCheck {
2222
public:
23-
AvoidNonConstGlobalVariablesCheck(StringRef Name, ClangTidyContext *Context)
24-
: ClangTidyCheck(Name, Context) {}
23+
AvoidNonConstGlobalVariablesCheck(StringRef Name, ClangTidyContext *Context);
2524
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
2625
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
26+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
27+
28+
private:
29+
const bool AllowInternalLinkage;
2730
};
2831

2932
} // namespace clang::tidy::cppcoreguidelines

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ Changes in existing checks
241241
false positives resulting from use of optionals in unevaluated context.
242242

243243
- Improved :doc:`bugprone-sizeof-expression
244-
<clang-tidy/checks/bugprone/sizeof-expression>` check by eliminating some
245-
false positives and adding a new (off-by-default) option
246-
`WarnOnSizeOfPointer` that reports all ``sizeof(pointer)`` expressions
247-
(except for a few that are idiomatic).
244+
<clang-tidy/checks/bugprone/sizeof-expression>` check by clarifying the
245+
diagnostics, eliminating some false positives and adding a new
246+
(off-by-default) option `WarnOnSizeOfPointer` that reports all
247+
``sizeof(pointer)`` expressions (except for a few that are idiomatic).
248248

249249
- Improved :doc:`bugprone-suspicious-include
250250
<clang-tidy/checks/bugprone/suspicious-include>` check by replacing the local
@@ -269,6 +269,11 @@ Changes in existing checks
269269
<clang-tidy/checks/bugprone/use-after-move>` check to also handle
270270
calls to ``std::forward``.
271271

272+
- Improved :doc:`cppcoreguidelines-avoid-non-const-global-variables
273+
<clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables>` check
274+
with a new option `AllowInternalLinkage` to disable the warning for variables
275+
with internal linkage.
276+
272277
- Improved :doc:`cppcoreguidelines-macro-usage
273278
<clang-tidy/checks/cppcoreguidelines/macro-usage>` check by ignoring macro with
274279
hash preprocessing token.

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,11 @@ The variables ``a``, ``c``, ``c_ptr1``, ``c_const_ptr`` and ``c_reference``
4141
will all generate warnings since they are either a non-const globally accessible
4242
variable, a pointer or a reference providing global access to non-const data
4343
or both.
44+
45+
Options
46+
-------
47+
48+
.. option:: AllowInternalLinkage
49+
50+
When set to `true`, static non-const variables and variables in anonymous
51+
namespaces will not generate a warning. The default value is `false`.

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-member-init.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
cppcoreguidelines-pro-type-member-init
44
======================================
55

6-
The check flags user-defined constructor definitions that do not
6+
The check flags user-provided constructor definitions that do not
77
initialize all fields that would be left in an undefined state by
88
default construction, e.g. builtins, pointers and record types without
99
user-provided default constructors containing at least one such

clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-2.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,24 @@ int Test5() {
3434

3535
int sum = 0;
3636
sum += sizeof(&S);
37-
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer
37+
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type
3838
sum += sizeof(__typeof(&S));
3939
sum += sizeof(&TS);
40-
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer
40+
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type
4141
sum += sizeof(__typeof(&TS));
4242
sum += sizeof(STRKWD MyStruct*);
4343
sum += sizeof(__typeof(STRKWD MyStruct*));
4444
sum += sizeof(TypedefStruct*);
4545
sum += sizeof(__typeof(TypedefStruct*));
4646
sum += sizeof(PTTS);
47-
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer
47+
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type
4848
sum += sizeof(PMyStruct);
4949
sum += sizeof(PS);
50-
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer
50+
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type
5151
sum += sizeof(PS2);
52-
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer
52+
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type
5353
sum += sizeof(&A10);
54-
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer
54+
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type
5555

5656
#ifdef __cplusplus
5757
MyStruct &rS = S;

0 commit comments

Comments
 (0)