Skip to content

Commit e98c1dd

Browse files
committed
Merge commit 'ca3ed7b2a0fdea7349242c2b63fcb049fc4a2b14' into llvmspirv_pulldown
2 parents 8040029 + ca3ed7b commit e98c1dd

File tree

1,460 files changed

+256080
-224474
lines changed

Some content is hidden

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

1,460 files changed

+256080
-224474
lines changed

.github/workflows/issue-release-workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
if: >-
7171
(github.repository == 'llvm/llvm-project') &&
7272
!startswith(github.event.comment.body, '<!--IGNORE-->') &&
73-
contains(github.event.comment.body, '/branch')
73+
contains(github.event.comment.body, '/branch ')
7474
7575
steps:
7676
- name: Fetch LLVM sources

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ class MCPlusBuilder {
170170
/// MCPlusBuilder classes must use convert/lower/create* interfaces instead.
171171
void setTailCall(MCInst &Inst);
172172

173+
public:
173174
/// Transfer annotations from \p SrcInst to \p DstInst.
174175
void moveAnnotations(MCInst &&SrcInst, MCInst &DstInst) const {
175176
assert(!getAnnotationInst(DstInst) &&
@@ -182,7 +183,6 @@ class MCPlusBuilder {
182183
removeAnnotationInst(SrcInst);
183184
}
184185

185-
public:
186186
/// Return iterator range covering def operands.
187187
iterator_range<MCInst::iterator> defOperands(MCInst &Inst) const {
188188
return make_range(Inst.begin(),

bolt/lib/Passes/FixRISCVCallsPass.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ void FixRISCVCallsPass::runOnFunction(BinaryFunction &BF) {
1919
auto *Target = MIB->getTargetSymbol(*II);
2020
assert(Target && "Cannot find call target");
2121

22+
MCInst OldCall = *II;
2223
auto L = BC.scopeLock();
2324

2425
if (MIB->isTailCall(*II))
2526
MIB->createTailCall(*II, Target, Ctx);
2627
else
2728
MIB->createCall(*II, Target, Ctx);
2829

30+
MIB->moveAnnotations(std::move(OldCall), *II);
2931
++II;
3032
continue;
3133
}
@@ -39,8 +41,19 @@ void FixRISCVCallsPass::runOnFunction(BinaryFunction &BF) {
3941
auto *Target = MIB->getTargetSymbol(*II);
4042
assert(Target && "Cannot find call target");
4143

44+
MCInst OldCall = *NextII;
4245
auto L = BC.scopeLock();
4346
MIB->createCall(*II, Target, Ctx);
47+
MIB->moveAnnotations(std::move(OldCall), *II);
48+
49+
// The original offset was set on the jalr of the auipc+jalr pair. Since
50+
// the whole pair is replaced by a call, adjust the offset by -4 (the
51+
// size of a auipc).
52+
if (std::optional<uint32_t> Offset = MIB->getOffset(*II)) {
53+
assert(*Offset >= 4 && "Illegal jalr offset");
54+
MIB->setOffset(*II, *Offset - 4);
55+
}
56+
4457
II = BB.eraseInstruction(NextII);
4558
continue;
4659
}

bolt/runtime/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
cmake_minimum_required(VERSION 3.20.0)
2+
include(CheckCXXCompilerFlag)
23
include(CheckIncludeFiles)
34
include(GNUInstallDirs)
45

@@ -33,7 +34,10 @@ if (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
3334
set(BOLT_RT_FLAGS ${BOLT_RT_FLAGS} "-mno-sse")
3435
endif()
3536
if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
36-
set(BOLT_RT_FLAGS ${BOLT_RT_FLAGS} "-mno-outline-atomics")
37+
check_cxx_compiler_flag("-mno-outline-atomics" CXX_SUPPORTS_OUTLINE_ATOMICS)
38+
if (CXX_SUPPORTS_OUTLINE_ATOMICS)
39+
set(BOLT_RT_FLAGS ${BOLT_RT_FLAGS} "-mno-outline-atomics")
40+
endif()
3741
endif()
3842

3943
# Don't let the compiler think it can create calls to standard libs

bolt/test/RISCV/call-annotations.s

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/// Test that annotations are properly carried over to fixed calls.
2+
/// Note that --enable-bat is used to force offsets to be kept.
3+
4+
// RUN: llvm-mc -triple riscv64 -filetype obj -o %t.o %s
5+
// RUN: ld.lld --emit-relocs -o %t %t.o
6+
// RUN: llvm-bolt --enable-bat --print-cfg --print-fix-riscv-calls \
7+
// RUN: --print-only=_start -o /dev/null %t | FileCheck %s
8+
9+
.text
10+
.global f
11+
.p2align 1
12+
f:
13+
ret
14+
.size f, .-f
15+
16+
// CHECK-LABEL: Binary Function "_start" after building cfg {
17+
// CHECK: auipc ra, f
18+
// CHECK-NEXT: jalr ra, -4(ra) # Offset: 4
19+
// CHECK-NEXT: jal ra, f # Offset: 8
20+
// CHECK-NEXT: jal zero, f # TAILCALL # Offset: 12
21+
22+
// CHECK-LABEL: Binary Function "_start" after fix-riscv-calls {
23+
// CHECK: call f # Offset: 0
24+
// CHECK-NEXT: call f # Offset: 8
25+
// CHECK-NEXT: tail f # TAILCALL # Offset: 12
26+
27+
.globl _start
28+
.p2align 1
29+
_start:
30+
call f
31+
jal f
32+
jal zero, f
33+
.size _start, .-_start

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ AST_MATCHER(CXXRecordDecl, isNotTriviallyCopyable) {
2222
} // namespace
2323

2424
void UndefinedMemoryManipulationCheck::registerMatchers(MatchFinder *Finder) {
25-
const auto NotTriviallyCopyableObject =
26-
hasType(ast_matchers::hasCanonicalType(
27-
pointsTo(cxxRecordDecl(isNotTriviallyCopyable()))));
25+
const auto HasNotTriviallyCopyableDecl =
26+
hasDeclaration(cxxRecordDecl(isNotTriviallyCopyable()));
27+
const auto ArrayOfNotTriviallyCopyable =
28+
arrayType(hasElementType(HasNotTriviallyCopyableDecl));
29+
const auto NotTriviallyCopyableObject = hasType(hasCanonicalType(
30+
anyOf(pointsTo(qualType(anyOf(HasNotTriviallyCopyableDecl,
31+
ArrayOfNotTriviallyCopyable))),
32+
ArrayOfNotTriviallyCopyable)));
2833

2934
// Check whether destination object is not TriviallyCopyable.
3035
// Applicable to all three memory manipulation functions.

clang-tools-extra/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace clang::tidy::bugprone {
1515

1616
/// Finds calls of memory manipulation functions ``memset()``, ``memcpy()`` and
17-
/// ``memmove()`` on not TriviallyCopyable objects resulting in undefined
17+
/// ``memmove()`` on non-TriviallyCopyable objects resulting in undefined
1818
/// behavior.
1919
///
2020
/// For the user-facing documentation see:

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

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -256,26 +256,6 @@ class RenamerClangTidyVisitor
256256
return true;
257257
}
258258

259-
// Fix type aliases in value declarations.
260-
if (const auto *Value = dyn_cast<ValueDecl>(Decl)) {
261-
if (const Type *TypePtr = Value->getType().getTypePtrOrNull()) {
262-
if (const auto *Typedef = TypePtr->getAs<TypedefType>())
263-
Check->addUsage(Typedef->getDecl(), Value->getSourceRange(), SM);
264-
}
265-
}
266-
267-
// Fix type aliases in function declarations.
268-
if (const auto *Value = dyn_cast<FunctionDecl>(Decl)) {
269-
if (const auto *Typedef =
270-
Value->getReturnType().getTypePtr()->getAs<TypedefType>())
271-
Check->addUsage(Typedef->getDecl(), Value->getSourceRange(), SM);
272-
for (const ParmVarDecl *Param : Value->parameters()) {
273-
if (const TypedefType *Typedef =
274-
Param->getType().getTypePtr()->getAs<TypedefType>())
275-
Check->addUsage(Typedef->getDecl(), Value->getSourceRange(), SM);
276-
}
277-
}
278-
279259
// Fix overridden methods
280260
if (const auto *Method = dyn_cast<CXXMethodDecl>(Decl)) {
281261
if (const CXXMethodDecl *Overridden = getOverrideMethod(Method)) {
@@ -340,6 +320,11 @@ class RenamerClangTidyVisitor
340320
return true;
341321
}
342322

323+
bool VisitTypedefTypeLoc(const TypedefTypeLoc &Loc) {
324+
Check->addUsage(Loc.getTypedefNameDecl(), Loc.getSourceRange(), SM);
325+
return true;
326+
}
327+
343328
bool VisitTagTypeLoc(const TagTypeLoc &Loc) {
344329
Check->addUsage(Loc.getDecl(), Loc.getSourceRange(), SM);
345330
return true;

clang-tools-extra/clangd/IncludeCleaner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ IncludeCleanerFindings computeIncludeCleanerFindings(ParsedAST &AST) {
390390
const auto &SM = AST.getSourceManager();
391391
include_cleaner::Includes ConvertedIncludes = convertIncludes(AST);
392392
const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID());
393-
auto *PreamblePatch = PreamblePatch::getPatchEntry(AST.tuPath(), SM);
393+
auto PreamblePatch = PreamblePatch::getPatchEntry(AST.tuPath(), SM);
394394

395395
std::vector<include_cleaner::SymbolReference> Macros =
396396
collectMacroReferences(AST);

clang-tools-extra/clangd/Preamble.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -953,12 +953,10 @@ const MainFileMacros &PreamblePatch::mainFileMacros() const {
953953
return PatchedMacros;
954954
}
955955

956-
const FileEntry *PreamblePatch::getPatchEntry(llvm::StringRef MainFilePath,
957-
const SourceManager &SM) {
956+
OptionalFileEntryRef PreamblePatch::getPatchEntry(llvm::StringRef MainFilePath,
957+
const SourceManager &SM) {
958958
auto PatchFilePath = getPatchName(MainFilePath);
959-
if (auto File = SM.getFileManager().getFile(PatchFilePath))
960-
return *File;
961-
return nullptr;
959+
return SM.getFileManager().getOptionalFileRef(PatchFilePath);
962960
}
963961
} // namespace clangd
964962
} // namespace clang

clang-tools-extra/clangd/Preamble.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ class PreamblePatch {
180180
const PreambleData &Baseline);
181181
/// Returns the FileEntry for the preamble patch of MainFilePath in SM, if
182182
/// any.
183-
static const FileEntry *getPatchEntry(llvm::StringRef MainFilePath,
184-
const SourceManager &SM);
183+
static OptionalFileEntryRef getPatchEntry(llvm::StringRef MainFilePath,
184+
const SourceManager &SM);
185185

186186
/// Adjusts CI (which compiles the modified inputs) to be used with the
187187
/// baseline preamble. This is done by inserting an artificial include to the

clang-tools-extra/clangd/index/SymbolCollector.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,14 +363,15 @@ class SymbolCollector::HeaderFileURICache {
363363
// named `Framework`, e.g. `NSObject.h` in framework `Foundation` would
364364
// give <Foundation/Foundation.h> if the umbrella header exists, otherwise
365365
// <Foundation/NSObject.h>.
366-
std::optional<llvm::StringRef> getFrameworkHeaderIncludeSpelling(
367-
const FileEntry *FE, llvm::StringRef Framework, HeaderSearch &HS) {
368-
auto Res = CachePathToFrameworkSpelling.try_emplace(FE->getName());
366+
std::optional<llvm::StringRef>
367+
getFrameworkHeaderIncludeSpelling(FileEntryRef FE, llvm::StringRef Framework,
368+
HeaderSearch &HS) {
369+
auto Res = CachePathToFrameworkSpelling.try_emplace(FE.getName());
369370
auto *CachedHeaderSpelling = &Res.first->second;
370371
if (!Res.second)
371372
return llvm::StringRef(*CachedHeaderSpelling);
372373

373-
auto HeaderPath = splitFrameworkHeaderPath(FE->getName());
374+
auto HeaderPath = splitFrameworkHeaderPath(FE.getName());
374375
if (!HeaderPath) {
375376
// Unexpected: must not be a proper framework header, don't cache the
376377
// failure.

clang-tools-extra/clangd/unittests/PreambleTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,9 +892,9 @@ TEST(PreamblePatch, PatchFileEntry) {
892892
}
893893
{
894894
auto AST = createPatchedAST(Code.code(), NewCode.code());
895-
auto *FE =
895+
auto FE =
896896
PreamblePatch::getPatchEntry(AST->tuPath(), AST->getSourceManager());
897-
ASSERT_NE(FE, nullptr);
897+
ASSERT_NE(FE, std::nullopt);
898898
EXPECT_THAT(FE->getName().str(),
899899
testing::EndsWith(PreamblePatch::HeaderName.str()));
900900
}

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ Changes in existing checks
202202
<clang-tidy/checks/bugprone/reserved-identifier>` check, so that it does not
203203
warn on macros starting with underscore and lowercase letter.
204204

205+
- Improved :doc:`bugprone-undefined-memory-manipulation
206+
<clang-tidy/checks/bugprone/undefined-memory-manipulation>` check to support
207+
fixed-size arrays of non-trivial types.
208+
205209
- Improved :doc:`cppcoreguidelines-avoid-non-const-global-variables
206210
<clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables>` check
207211
to ignore ``static`` variables declared within the scope of
@@ -291,7 +295,9 @@ Changes in existing checks
291295
warnings when a type's forward declaration precedes its definition.
292296
Additionally, it now provides appropriate warnings for ``struct`` and
293297
``union`` in C, while also incorporating support for the
294-
``Leading_upper_snake_case`` naming convention.
298+
``Leading_upper_snake_case`` naming convention. The handling of ``typedef``
299+
has been enhanced, particularly within complex types like function pointers
300+
and cases where style checks were omitted when functions started with macros.
295301

296302
- Improved :doc:`readability-implicit-bool-conversion
297303
<clang-tidy/checks/readability/implicit-bool-conversion>` check to take

clang-tools-extra/docs/clang-tidy/checks/bugprone/undefined-memory-manipulation.rst

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,31 @@ bugprone-undefined-memory-manipulation
44
======================================
55

66
Finds calls of memory manipulation functions ``memset()``, ``memcpy()`` and
7-
``memmove()`` on not TriviallyCopyable objects resulting in undefined behavior.
7+
``memmove()`` on non-TriviallyCopyable objects resulting in undefined behavior.
8+
9+
Using memory manipulation functions on non-TriviallyCopyable objects can lead
10+
to a range of subtle and challenging issues in C++ code. The most immediate
11+
concern is the potential for undefined behavior, where the state of the object
12+
may become corrupted or invalid. This can manifest as crashes, data corruption,
13+
or unexpected behavior at runtime, making it challenging to identify and
14+
diagnose the root cause. Additionally, misuse of memory manipulation functions
15+
can bypass essential object-specific operations, such as constructors and
16+
destructors, leading to resource leaks or improper initialization.
17+
18+
For example, when using ``memcpy`` to copy ``std::string``, pointer data is
19+
being copied, and it can result in a double free issue.
20+
21+
.. code-block:: c++
22+
23+
#include <cstring>
24+
#include <string>
25+
26+
int main() {
27+
std::string source = "Hello";
28+
std::string destination;
29+
30+
std::memcpy(&destination, &source, sizeof(std::string));
31+
32+
// Undefined behavior may occur here, during std::string destructor call.
33+
return 0;
34+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %check_clang_tidy %s bugprone-inc-dec-in-conditions %t
2+
3+
_BitInt(8) v_401_0() {
4+
0 && ({
5+
_BitInt(5) y = 0;
6+
16777215wb ?: ++y;
7+
});
8+
}
9+
// CHECK-MESSAGES: warning

clang-tools-extra/test/clang-tidy/checkers/bugprone/undefined-memory-manipulation.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ void notTriviallyCopyable() {
126126
::memmove(&p, &vb, sizeof(int));
127127
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, source object type 'types::VirtualBase'
128128

129+
types::Copy ca[10];
130+
memset(ca, 0, sizeof(ca));
131+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object type 'types::Copy[10]'
132+
memset(&ca, 0, sizeof(ca));
133+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object type 'types::Copy[10]'
134+
129135
#define MEMSET memset(&vf, 0, sizeof(int));
130136
MEMSET
131137
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object type 'types::VirtualFunc'
@@ -159,6 +165,17 @@ void notTriviallyCopyable() {
159165
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object type 'aliases::Copy2'
160166
memset(pc3, 0, sizeof(int));
161167
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object type 'Copy3'
168+
using Copy3Arr = Copy3[5];
169+
Copy3Arr c3a;
170+
memset(c3a, 0, sizeof(c3a));
171+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object type 'Copy3Arr'
172+
memset(&c3a, 0, sizeof(c3a));
173+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object type 'Copy3Arr'
174+
175+
typedef Copy3 Copy3Arr2[5];
176+
Copy3Arr2 c3a2;
177+
memset(c3a2, 0, sizeof(c3a2));
178+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object type 'Copy3Arr2'
162179
}
163180

164181
void triviallyCopyable() {

clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,3 +729,29 @@ struct forward_declared_as_struct;
729729
class forward_declared_as_struct {
730730
};
731731

732+
namespace pr55156 {
733+
734+
template<typename> struct Wrap;
735+
736+
typedef enum {
737+
VALUE0,
738+
VALUE1,
739+
} ValueType;
740+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: invalid case style for typedef 'ValueType' [readability-identifier-naming]
741+
// CHECK-FIXES: {{^}}} value_type_t;
742+
743+
typedef ValueType (*MyFunPtr)(const ValueType&, Wrap<ValueType>*);
744+
// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for typedef 'MyFunPtr' [readability-identifier-naming]
745+
// CHECK-FIXES: {{^}}typedef value_type_t (*my_fun_ptr_t)(const value_type_t&, Wrap<value_type_t>*);
746+
747+
#define STATIC_MACRO static
748+
STATIC_MACRO void someFunc(ValueType a_v1, const ValueType& a_v2) {}
749+
// CHECK-FIXES: {{^}}STATIC_MACRO void someFunc(value_type_t a_v1, const value_type_t& a_v2) {}
750+
STATIC_MACRO void someFunc(const ValueType** p_a_v1, ValueType (*p_a_v2)()) {}
751+
// CHECK-FIXES: {{^}}STATIC_MACRO void someFunc(const value_type_t** p_a_v1, value_type_t (*p_a_v2)()) {}
752+
STATIC_MACRO ValueType someFunc() {}
753+
// CHECK-FIXES: {{^}}STATIC_MACRO value_type_t someFunc() {}
754+
STATIC_MACRO void someFunc(MyFunPtr, const MyFunPtr****) {}
755+
// CHECK-FIXES: {{^}}STATIC_MACRO void someFunc(my_fun_ptr_t, const my_fun_ptr_t****) {}
756+
#undef STATIC_MACRO
757+
}

0 commit comments

Comments
 (0)