Skip to content

Commit 7ce30e5

Browse files
committed
Merged main:941c75a53036 into amd-gfx:ff5630892f5f563d
Local branch amd-gfx ff56308 Merged main:5099dc341f7f into amd-gfx:ab27814b3805 Remote branch main 941c75a [ValueTracking] Return ConstantRange instead of setting limits (NFC)
2 parents ff56308 + 941c75a commit 7ce30e5

File tree

147 files changed

+6740
-4562
lines changed

Some content is hidden

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

147 files changed

+6740
-4562
lines changed

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,9 @@ static bool checkOffsets(const typename ELFT::Phdr &Phdr,
408408
return true;
409409

410410
// Only non-empty sections can be at the end of a segment.
411-
uint64_t SectionSize = Sec.sh_size ? Sec.sh_size : 1;
412-
AddressRange SectionAddressRange(Sec.sh_offset, Sec.sh_offset + SectionSize);
411+
uint64_t SectionSize = Sec.sh_size ? Sec.sh_size : 1ull;
412+
AddressRange SectionAddressRange((uint64_t)Sec.sh_offset,
413+
Sec.sh_offset + SectionSize);
413414
AddressRange SegmentAddressRange(Phdr.p_offset,
414415
Phdr.p_offset + Phdr.p_filesz);
415416
if (SegmentAddressRange.contains(SectionAddressRange))
@@ -425,8 +426,9 @@ template <class ELFT>
425426
static bool checkVMA(const typename ELFT::Phdr &Phdr,
426427
const typename ELFT::Shdr &Sec, bool &Overlap) {
427428
// Only non-empty sections can be at the end of a segment.
428-
uint64_t SectionSize = Sec.sh_size ? Sec.sh_size : 1;
429-
AddressRange SectionAddressRange(Sec.sh_addr, Sec.sh_addr + SectionSize);
429+
uint64_t SectionSize = Sec.sh_size ? Sec.sh_size : 1ull;
430+
AddressRange SectionAddressRange((uint64_t)Sec.sh_addr,
431+
Sec.sh_addr + SectionSize);
430432
AddressRange SegmentAddressRange(Phdr.p_vaddr, Phdr.p_vaddr + Phdr.p_memsz);
431433

432434
if (SegmentAddressRange.contains(SectionAddressRange))

bolt/test/checkvma-large-section.test

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This test reproduces the issue with a section which ends at >4G address
2+
REQUIRES: asserts
3+
RUN: split-file %s %t
4+
RUN: yaml2obj %t/yaml -o %t.exe --max-size=0
5+
RUN: llvm-bolt %t.exe -o /dev/null --allow-stripped
6+
#--- yaml
7+
--- !ELF
8+
FileHeader:
9+
Class: ELFCLASS64
10+
Data: ELFDATA2LSB
11+
Type: ET_EXEC
12+
Machine: EM_X86_64
13+
ProgramHeaders:
14+
- Type: PT_LOAD
15+
FirstSec: .a
16+
LastSec: .a
17+
Align: 0x1000
18+
- Type: PT_LOAD
19+
Flags: [ PF_R, PF_W ]
20+
FirstSec: .large_sec
21+
LastSec: .large_sec
22+
VAddr: 0x4a0279a8
23+
- Type: PT_GNU_RELRO
24+
Flags: [ PF_R ]
25+
Sections:
26+
- Name: .a
27+
Type: SHT_PROGBITS
28+
Content: 00
29+
AddressAlign: 0x1
30+
- Name: .large_sec
31+
Type: SHT_PROGBITS
32+
Flags: [ SHF_WRITE, SHF_ALLOC ]
33+
Address: 0x4a0279a8
34+
Size: 0xdf8bb1a0
35+
...

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
6161
// before the typedef will be the nested one (PR#50990). Therefore, we also
6262
// keep track of the parent declaration, so that we can look up the last
6363
// TagDecl that is a sibling of the typedef in the AST.
64-
LastTagDeclRanges[ParentDecl] = MatchedTagDecl->getSourceRange();
64+
if (MatchedTagDecl->isThisDeclarationADefinition())
65+
LastTagDeclRanges[ParentDecl] = MatchedTagDecl->getSourceRange();
6566
return;
6667
}
6768

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ Changes in existing checks
279279
fixes for reordering arguments.
280280

281281
- Improved :doc:`modernize-use-using
282-
<clang-tidy/checks/modernize/use-using>` check to fix function pointer
283-
``typedef`` correctly.
282+
<clang-tidy/checks/modernize/use-using>` check to fix function pointer and
283+
forward declared ``typedef`` correctly.
284284

285285
- Improved :doc:`performance-faster-string-find
286286
<clang-tidy/checks/performance/faster-string-find>` check to properly escape

clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,7 @@ typedef bool (*ISSUE_65055_2)(int);
321321
// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use 'using' instead of 'typedef'
322322
// CHECK-FIXES: {{^}}using ISSUE_65055_1 = void (*)(int);{{$}}
323323
// CHECK-FIXES: {{^}}using ISSUE_65055_2 = bool (*)(int);{{$}}
324+
325+
typedef class ISSUE_67529_1 *ISSUE_67529;
326+
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
327+
// CHECK-FIXES: using ISSUE_67529 = class ISSUE_67529_1 *;

clang/cmake/caches/CrossWinToARMLinux.cmake

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS
151151

152152
find_package(Python3 COMPONENTS Interpreter)
153153

154+
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_TEST_PARAMS_default "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_TEST_PARAMS}")
155+
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_TEST_PARAMS_default "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_TEST_PARAMS}")
156+
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_TEST_PARAMS_default "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_TEST_PARAMS}")
157+
154158
# Remote test configuration.
155159
if(DEFINED REMOTE_TEST_HOST)
156160
# Allow override with the custom values.
@@ -162,11 +166,15 @@ if(DEFINED REMOTE_TEST_HOST)
162166
"\\\"${Python3_EXECUTABLE}\\\" \\\"${LLVM_PROJECT_DIR}/llvm/utils/remote-exec.py\\\" --host=${REMOTE_TEST_USER}@${REMOTE_TEST_HOST}"
163167
CACHE STRING "")
164168

165-
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_TEST_PARAMS "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_TEST_PARAMS} 'executor=${DEFAULT_TEST_EXECUTOR}'" CACHE STRING "")
166-
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_TEST_PARAMS "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_TEST_PARAMS} 'executor=${DEFAULT_TEST_EXECUTOR}'" CACHE STRING "")
167-
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_TEST_PARAMS "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_TEST_PARAMS} 'executor=${DEFAULT_TEST_EXECUTOR}'" CACHE STRING "")
169+
list(APPEND RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_TEST_PARAMS_default "executor=${DEFAULT_TEST_EXECUTOR}")
170+
list(APPEND RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_TEST_PARAMS_default "executor=${DEFAULT_TEST_EXECUTOR}")
171+
list(APPEND RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_TEST_PARAMS_default "executor=${DEFAULT_TEST_EXECUTOR}")
168172
endif()
169173

174+
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_TEST_PARAMS "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_TEST_PARAMS_default}" CACHE INTERNAL "")
175+
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_TEST_PARAMS "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_TEST_PARAMS_default}" CACHE INTERNAL "")
176+
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_TEST_PARAMS "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_TEST_PARAMS_default}" CACHE INTERNAL "")
177+
170178
set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")
171179
set(LLVM_TOOLCHAIN_TOOLS
172180
llvm-ar

clang/docs/ClangOffloadBundler.rst

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -309,30 +309,3 @@ target by comparing bundle ID's. Two bundle ID's are considered compatible if:
309309
* Their offload kind are the same
310310
* Their target triple are the same
311311
* Their GPUArch are the same
312-
313-
Compression and Decompression
314-
=============================
315-
316-
``clang-offload-bundler`` provides features to compress and decompress the full
317-
bundle, leveraging inherent redundancies within the bundle entries. Use the
318-
`-compress` command-line option to enable this compression capability.
319-
320-
The compressed offload bundle begins with a header followed by the compressed binary data:
321-
322-
- **Magic Number (4 bytes)**:
323-
This is a unique identifier to distinguish compressed offload bundles. The value is the string 'CCOB' (Compressed Clang Offload Bundle).
324-
325-
- **Version Number (16-bit unsigned int)**:
326-
This denotes the version of the compressed offload bundle format. The current version is `1`.
327-
328-
- **Compression Method (16-bit unsigned int)**:
329-
This field indicates the compression method used. The value corresponds to either `zlib` or `zstd`, represented as a 16-bit unsigned integer cast from the LLVM compression enumeration.
330-
331-
- **Uncompressed Binary Size (32-bit unsigned int)**:
332-
This is the size (in bytes) of the binary data before it was compressed.
333-
334-
- **Hash (64-bit unsigned int)**:
335-
This is a 64-bit truncated MD5 hash of the uncompressed binary data. It serves for verification and caching purposes.
336-
337-
- **Compressed Data**:
338-
The actual compressed binary data follows the header. Its size can be inferred from the total size of the file minus the header size.

clang/docs/ReleaseNotes.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ C Language Changes
132132
- ``structs``, ``unions``, and ``arrays`` that are const may now be used as
133133
constant expressions. This change is more consistent with the behavior of
134134
GCC.
135+
- Clang now supports the C-only attribute ``counted_by``. When applied to a
136+
struct's flexible array member, it points to the struct field that holds the
137+
number of elements in the flexible array member. This information can improve
138+
the results of the array bound sanitizer and the
139+
``__builtin_dynamic_object_size`` builtin.
135140

136141
C23 Feature Support
137142
^^^^^^^^^^^^^^^^^^^
@@ -146,6 +151,13 @@ Non-comprehensive list of changes in this release
146151

147152
New Compiler Flags
148153
------------------
154+
* ``-fverify-intermediate-code`` and its complement ``-fno-verify-intermediate-code``.
155+
Enables or disables verification of the generated LLVM IR.
156+
Users can pass this to turn on extra verification to catch certain types of
157+
compiler bugs at the cost of extra compile time.
158+
Since enabling the verifier adds a non-trivial cost of a few percent impact on
159+
build times, it's disabled by default, unless your LLVM distribution itself is
160+
compiled with runtime checks enabled.
149161

150162
Deprecated Compiler Flags
151163
-------------------------
@@ -327,6 +339,9 @@ Bug Fixes in This Version
327339
(`#64462 <https://github.com/llvm/llvm-project/issues/64462>`_)
328340
- Fixes a regression where the ``UserDefinedLiteral`` was not properly preserved
329341
while evaluating consteval functions. (`#63898 <https://github.com/llvm/llvm-project/issues/63898>`_).
342+
- Fix a crash when evaluating value-dependent structured binding
343+
variables at compile time.
344+
Fixes (`#67690 <https://github.com/llvm/llvm-project/issues/67690>`_)
330345

331346
Bug Fixes to Compiler Builtins
332347
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/AST/Decl.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4304,6 +4304,30 @@ class RecordDecl : public TagDecl {
43044304
return field_begin() == field_end();
43054305
}
43064306

4307+
FieldDecl *getLastField() {
4308+
FieldDecl *FD = nullptr;
4309+
for (FieldDecl *Field : fields())
4310+
FD = Field;
4311+
return FD;
4312+
}
4313+
const FieldDecl *getLastField() const {
4314+
return const_cast<RecordDecl *>(this)->getLastField();
4315+
}
4316+
4317+
template <typename Functor>
4318+
const FieldDecl *findFieldIf(Functor &Pred) const {
4319+
for (const Decl *D : decls()) {
4320+
if (const auto *FD = dyn_cast<FieldDecl>(D); FD && Pred(FD))
4321+
return FD;
4322+
4323+
if (const auto *RD = dyn_cast<RecordDecl>(D))
4324+
if (const FieldDecl *FD = RD->findFieldIf(Pred))
4325+
return FD;
4326+
}
4327+
4328+
return nullptr;
4329+
}
4330+
43074331
/// Note that the definition of this type is now complete.
43084332
virtual void completeDefinition();
43094333

clang/include/clang/AST/DeclBase.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "clang/AST/DeclarationName.h"
1919
#include "clang/Basic/IdentifierTable.h"
2020
#include "clang/Basic/LLVM.h"
21+
#include "clang/Basic/LangOptions.h"
2122
#include "clang/Basic/SourceLocation.h"
2223
#include "clang/Basic/Specifiers.h"
2324
#include "llvm/ADT/ArrayRef.h"
@@ -477,6 +478,15 @@ class alignas(8) Decl {
477478
// Return true if this is a FileContext Decl.
478479
bool isFileContextDecl() const;
479480

481+
/// Whether it resembles a flexible array member. This is a static member
482+
/// because we want to be able to call it with a nullptr. That allows us to
483+
/// perform non-Decl specific checks based on the object's type and strict
484+
/// flex array level.
485+
static bool isFlexibleArrayMemberLike(
486+
ASTContext &Context, const Decl *D, QualType Ty,
487+
LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel,
488+
bool IgnoreTemplateOrMacroSubstitution);
489+
480490
ASTContext &getASTContext() const LLVM_READONLY;
481491

482492
/// Helper to get the language options from the ASTContext.

clang/include/clang/Basic/Attr.td

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4246,3 +4246,21 @@ def AvailableOnlyInDefaultEvalMethod : InheritableAttr {
42464246
let Subjects = SubjectList<[TypedefName], ErrorDiag>;
42474247
let Documentation = [Undocumented];
42484248
}
4249+
4250+
def CountedBy : InheritableAttr {
4251+
let Spellings = [Clang<"counted_by">];
4252+
let Subjects = SubjectList<[Field]>;
4253+
let Args = [IdentifierArgument<"CountedByField">];
4254+
let Documentation = [CountedByDocs];
4255+
let LangOpts = [COnly];
4256+
// FIXME: This is ugly. Let using a DeclArgument would be nice, but a Decl
4257+
// isn't yet available due to the fact that we're still parsing the
4258+
// structure. Maybe that code could be changed sometime in the future.
4259+
code AdditionalMembers = [{
4260+
private:
4261+
SourceRange CountedByFieldLoc;
4262+
public:
4263+
SourceRange getCountedByFieldLoc() const { return CountedByFieldLoc; }
4264+
void setCountedByFieldLoc(SourceRange Loc) { CountedByFieldLoc = Loc; }
4265+
}];
4266+
}

clang/include/clang/Basic/AttrDocs.td

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7275,3 +7275,69 @@ relative ordering of values is important. For example:
72757275
attribute, they default to the value ``65535``.
72767276
}];
72777277
}
7278+
7279+
def CountedByDocs : Documentation {
7280+
let Category = DocCatField;
7281+
let Content = [{
7282+
Clang supports the ``counted_by`` attribute on the flexible array member of a
7283+
structure in C. The argument for the attribute is the name of a field member in
7284+
the same structure holding the count of elements in the flexible array. This
7285+
information can be used to improve the results of the array bound sanitizer and
7286+
the ``__builtin_dynamic_object_size`` builtin.
7287+
7288+
For example, the following code:
7289+
7290+
.. code-block:: c
7291+
7292+
struct bar;
7293+
7294+
struct foo {
7295+
size_t count;
7296+
char other;
7297+
struct bar *array[] __attribute__((counted_by(count)));
7298+
};
7299+
7300+
specifies that the flexible array member ``array`` has the number of elements
7301+
allocated for it stored in ``count``. This establishes a relationship between
7302+
``array`` and ``count``. Specifically, ``p->array`` must have at least
7303+
``p->count`` number of elements available. It's the user's responsibility to
7304+
ensure that this relationship is maintained through changes to the structure.
7305+
7306+
In the following example, the allocated array erroneously has fewer elements
7307+
than what's specified by ``p->count``. This would result in an out-of-bounds
7308+
access not being detected.
7309+
7310+
.. code-block:: c
7311+
7312+
#define SIZE_INCR 42
7313+
7314+
struct foo *p;
7315+
7316+
void foo_alloc(size_t count) {
7317+
p = malloc(MAX(sizeof(struct foo),
7318+
offsetof(struct foo, array[0]) + count * sizeof(struct bar *)));
7319+
p->count = count + SIZE_INCR;
7320+
}
7321+
7322+
The next example updates ``p->count``, breaking the relationship requirement
7323+
that ``p->array`` must have at least ``p->count`` number of elements available:
7324+
7325+
.. code-block:: c
7326+
7327+
#define SIZE_INCR 42
7328+
7329+
struct foo *p;
7330+
7331+
void foo_alloc(size_t count) {
7332+
p = malloc(MAX(sizeof(struct foo),
7333+
offsetof(struct foo, array[0]) + count * sizeof(struct bar *)));
7334+
p->count = count;
7335+
}
7336+
7337+
void use_foo(int index) {
7338+
p->count += SIZE_INCR + 1; /* 'count' is now larger than the number of elements of 'array'. */
7339+
p->array[index] = 0; /* the sanitizer can't properly check if this is an out-of-bounds access. */
7340+
}
7341+
7342+
}];
7343+
}

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6383,6 +6383,21 @@ def warn_superclass_variable_sized_type_not_at_end : Warning<
63836383
"field %0 can overwrite instance variable %1 with variable sized type %2"
63846384
" in superclass %3">, InGroup<ObjCFlexibleArray>;
63856385

6386+
def err_counted_by_attr_not_on_flexible_array_member : Error<
6387+
"'counted_by' only applies to flexible array members">;
6388+
def err_flexible_array_counted_by_attr_field_not_found : Error<
6389+
"field %0 in 'counted_by' not found">;
6390+
def err_flexible_array_counted_by_attr_field_not_found_suggest : Error<
6391+
"field %0 in 'counted_by' not found; did you mean %1?">;
6392+
def err_flexible_array_counted_by_attr_field_not_found_in_struct : Error<
6393+
"field %0 in 'counted_by' is not found in struct">;
6394+
def err_flexible_array_counted_by_attr_refers_to_self : Error<
6395+
"field %0 in 'counted_by' cannot refer to the flexible array">;
6396+
def err_flexible_array_counted_by_attr_field_not_integer : Error<
6397+
"field %0 in 'counted_by' is not a non-boolean integer type">;
6398+
def note_flexible_array_counted_by_attr_field : Note<
6399+
"field %0 declared here">;
6400+
63866401
let CategoryName = "ARC Semantic Issue" in {
63876402

63886403
// ARC-mode diagnostics.

clang/include/clang/Basic/ObjCRuntime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ class ObjCRuntime {
483483
}
484484

485485
template <typename HasherT, llvm::support::endianness Endianness>
486-
friend void addHash(llvm::HashBuilderImpl<HasherT, Endianness> &HBuilder,
486+
friend void addHash(llvm::HashBuilder<HasherT, Endianness> &HBuilder,
487487
const ObjCRuntime &OCR) {
488488
HBuilder.add(OCR.getKind(), OCR.getVersion());
489489
}

clang/include/clang/Basic/Sanitizers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class SanitizerMask {
7878
llvm::hash_code hash_value() const;
7979

8080
template <typename HasherT, llvm::support::endianness Endianness>
81-
friend void addHash(llvm::HashBuilderImpl<HasherT, Endianness> &HBuilder,
81+
friend void addHash(llvm::HashBuilder<HasherT, Endianness> &HBuilder,
8282
const SanitizerMask &SM) {
8383
HBuilder.addRange(&SM.maskLoToHigh[0], &SM.maskLoToHigh[kNumElem]);
8484
}

0 commit comments

Comments
 (0)