Skip to content

Commit 7718c2d

Browse files
authored
merge main into amd-staging (llvm#3632)
2 parents 97b9c86 + 0c4265c commit 7718c2d

File tree

158 files changed

+4530
-1601
lines changed

Some content is hidden

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

158 files changed

+4530
-1601
lines changed

.github/workflows/libclang-python-tests.yml

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ permissions:
44
contents: read
55

66
on:
7-
workflow_dispatch:
87
push:
98
branches:
109
- 'main'
@@ -13,29 +12,46 @@ on:
1312
- 'clang/tools/libclang/**'
1413
- 'clang/CMakeList.txt'
1514
- '.github/workflows/libclang-python-tests.yml'
16-
- '.github/workflows/llvm-project-tests.yml'
1715
pull_request:
1816
paths:
1917
- 'clang/bindings/python/**'
2018
- 'clang/tools/libclang/**'
2119
- 'clang/CMakeList.txt'
2220
- '.github/workflows/libclang-python-tests.yml'
23-
- '.github/workflows/llvm-project-tests.yml'
2421

2522
jobs:
2623
check-clang-python:
2724
# Build libclang and then run the libclang Python binding's unit tests.
25+
# There is an issue running on "windows-2019".
26+
# See https://github.com/llvm/llvm-project/issues/76601#issuecomment-1873049082.
2827
name: Build and run Python unit tests
2928
if: github.repository == 'llvm/llvm-project'
29+
runs-on: ubuntu-24.04
3030
strategy:
3131
fail-fast: false
3232
matrix:
3333
python-version: ["3.8", "3.13"]
34-
uses: ./.github/workflows/llvm-project-tests.yml
35-
with:
36-
build_target: check-clang-python
37-
projects: clang
38-
# There is an issue running on "windows-2019".
39-
# See https://github.com/llvm/llvm-project/issues/76601#issuecomment-1873049082.
40-
os_list: '["ubuntu-24.04"]'
41-
python_version: ${{ matrix.python-version }}
34+
steps:
35+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
36+
- name: Setup Python
37+
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
38+
with:
39+
python-version: ${{ matrix.python-version }}
40+
- name: Setup ccache
41+
uses: hendrikmuhs/ccache-action@a1209f81afb8c005c13b4296c32e363431bffea5 # v1.2.17
42+
with:
43+
max-size: 2G
44+
key: spirv-ubuntu-24.04
45+
variant: sccache
46+
- name: Build and Test
47+
run: |
48+
mkdir build
49+
cmake -GNinja \
50+
-S llvm \
51+
-B build \
52+
-DCMAKE_BUILD_TYPE=Release \
53+
-DLLVM_ENABLE_ASSERTIONS=ON \
54+
-DCMAKE_C_COMPILER_LAUNCHER=sccache \
55+
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache \
56+
-DLLVM_ENABLE_PROJECTS=clang
57+
ninja -C build check-clang-python

.github/workflows/mlir-spirv-tests.yml

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,28 @@ jobs:
2424
check_spirv:
2525
if: github.repository_owner == 'llvm'
2626
name: Test MLIR SPIR-V
27-
uses: ./.github/workflows/llvm-project-tests.yml
28-
with:
29-
build_target: check-mlir
30-
projects: mlir
31-
extra_cmake_args: '-DLLVM_TARGETS_TO_BUILD="host" -DLLVM_INCLUDE_SPIRV_TOOLS_TESTS=ON'
32-
os_list: '["ubuntu-24.04"]'
27+
runs-on: ubuntu-24.04
28+
container:
29+
image: ghcr.io/llvm/ci-ubuntu-24.04:latest
30+
steps:
31+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
32+
- name: Setup ccache
33+
uses: hendrikmuhs/ccache-action@a1209f81afb8c005c13b4296c32e363431bffea5 # v1.2.17
34+
with:
35+
max-size: 2G
36+
key: spirv-mlir-ubuntu-24.04
37+
variant: sccache
38+
- name: Build and Test
39+
run: |
40+
mkdir build
41+
cmake -GNinja \
42+
-S llvm \
43+
-B build \
44+
-DCMAKE_BUILD_TYPE=Release \
45+
-DLLVM_ENABLE_ASSERTIONS=ON \
46+
-DCMAKE_C_COMPILER_LAUNCHER=sccache \
47+
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache \
48+
-DLLVM_TARGETS_TO_BUILD="host" \
49+
-DLLVM_INCLUDE_SPIRV_TOOLS_TESTS=ON \
50+
-DLLVM_ENABLE_PROJECTS=mlir
51+
ninja -C build check-mlir

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,8 @@ Bug Fixes in This Version
439439
targets that treat ``_Float16``/``__fp16`` as native scalar types. Previously
440440
the warning was silently lost because the operands differed only by an implicit
441441
cast chain. (#GH149967).
442+
- Fixed a crash with incompatible pointer to integer conversions in designated
443+
initializers involving string literals. (#GH154046)
442444

443445
Bug Fixes to Compiler Builtins
444446
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/docs/SourceBasedCodeCoverage.rst

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ supported. Uninstrumented code simply won't be accounted for in reports.
6666

6767
To compile code with Modified Condition/Decision Coverage (MC/DC) enabled,
6868
pass ``-fcoverage-mcdc`` in addition to the clang options specified above.
69-
MC/DC is an advanced form of code coverage most applicable in the embedded
69+
MC/DC is an advanced form of code coverage most applicable to the embedded
7070
space.
7171

7272
Running the instrumented program
7373
================================
7474

75-
The next step is to run the instrumented program. When the program exits it
75+
The next step is to run the instrumented program. When the program exits, it
7676
will write a **raw profile** to the path specified by the ``LLVM_PROFILE_FILE``
7777
environment variable. If that variable does not exist, the profile is written
7878
to ``default.profraw`` in the current directory of the program. If
79-
``LLVM_PROFILE_FILE`` contains a path to a non-existent directory, the missing
79+
``LLVM_PROFILE_FILE`` specifies a path to a non-existent directory, the missing
8080
directory structure will be created. Additionally, the following special
8181
**pattern strings** are rewritten:
8282

@@ -97,7 +97,7 @@ directory structure will be created. Additionally, the following special
9797
* "%b" expands out to the binary ID (build ID). It can be used with "%Nm" to
9898
avoid binary signature collisions. To use it, the program should be compiled
9999
with the build ID linker option (``--build-id`` for GNU ld or LLD,
100-
``/build-id`` for lld-link on Windows). Linux, Windows and AIX are supported.
100+
``/build-id`` for lld-link on Windows). Linux, Windows, and AIX are supported.
101101

102102
* "%c" expands out to nothing, but enables a mode in which profile counter
103103
updates are continuously synced to a file. This means that if the
@@ -128,7 +128,7 @@ and set bias to the offset between the original and the new counter location,
128128
at which point every subsequent counter access will be to the new location,
129129
which allows updating profile directly akin to the continuous mode.
130130

131-
The advantage of this approach is that doesn't require any special OS support.
131+
The advantage of this approach is that it doesn't require any special OS support.
132132
The disadvantage is the extra overhead due to additional instructions required
133133
for each counter access (overhead both in terms of binary size and performance)
134134
plus duplication of counters (i.e. one copy in the binary itself and another
@@ -137,7 +137,7 @@ other platforms by passing the ``-runtime-counter-relocation`` option to the
137137
backend during compilation.
138138

139139
For a program such as the `Lit <https://llvm.org/docs/CommandGuide/lit.html>`_
140-
testing tool which invokes other programs, it may be necessary to set
140+
testing tool, which invokes other programs, it may be necessary to set
141141
``LLVM_PROFILE_FILE`` for each invocation. The pattern strings "%p" or "%Nm"
142142
may help to avoid corruption due to concurrency. Note that "%p" is also a Lit
143143
token and needs to be escaped as "%%p".
@@ -149,7 +149,7 @@ token and needs to be escaped as "%%p".
149149
Creating coverage reports
150150
=========================
151151

152-
Raw profiles have to be **indexed** before they can be used to generate
152+
Raw profiles must be **indexed** before they can be used to generate
153153
coverage reports. This is done using the "merge" tool in ``llvm-profdata``
154154
(which can combine multiple raw profiles and index them at the same time):
155155

@@ -240,13 +240,13 @@ line-oriented report, try:
240240
TOTAL 13 0 100.00% 3 0 100.00% 13 0 100.00% 12 2 83.33%
241241
242242
The ``llvm-cov`` tool supports specifying a custom demangler, writing out
243-
reports in a directory structure, and generating html reports. For the full
243+
reports in a directory structure, and generating HTML reports. For the full
244244
list of options, please refer to the `command guide
245245
<https://llvm.org/docs/CommandGuide/llvm-cov.html>`_.
246246

247247
A few final notes:
248248

249-
* The ``-sparse`` flag is optional but can result in dramatically smaller
249+
* The ``-sparse`` flag is optional but can produce dramatically smaller
250250
indexed profiles. This option should not be used if the indexed profile will
251251
be reused for PGO.
252252

@@ -255,7 +255,7 @@ A few final notes:
255255
information directly into an existing raw profile on disk. The details are
256256
out of scope.
257257

258-
* The ``llvm-profdata`` tool can be used to merge together multiple raw or
258+
* The ``llvm-profdata`` tool can be used to merge multiple raw or
259259
indexed profiles. To combine profiling data from multiple runs of a program,
260260
try e.g:
261261

@@ -299,7 +299,7 @@ There are six statistics tracked in a coverage summary:
299299
source code that may each evaluate to either "true" or "false". These
300300
conditions may comprise larger boolean expressions linked by boolean logical
301301
operators. For example, "x = (y == 2) || (z < 10)" is a boolean expression
302-
that is comprised of two individual conditions, each of which evaluates to
302+
comprised of two individual conditions, each of which evaluates to
303303
either true or false, producing four total branch outcomes.
304304

305305
* Modified Condition/Decision Coverage (MC/DC) is the percentage of individual
@@ -316,7 +316,7 @@ There are six statistics tracked in a coverage summary:
316316
``-show-mcdc-summary`` option as long as code was also compiled using the
317317
clang option ``-fcoverage-mcdc``.
318318

319-
* Boolean expressions that are only comprised of one condition (and therefore
319+
* Boolean expressions comprised of only one condition (and therefore
320320
have no logical operators) are not included in MC/DC analysis and are
321321
trivially deducible using branch coverage.
322322

@@ -366,7 +366,7 @@ By default the compiler runtime uses a static initializer to determine the
366366
profile output path and to register a writer function. To collect profiles
367367
without using static initializers, do this manually:
368368

369-
* Export a ``int __llvm_profile_runtime`` symbol from each instrumented shared
369+
* Export an ``int __llvm_profile_runtime`` symbol from each instrumented shared
370370
library and executable. When the linker finds a definition of this symbol, it
371371
knows to skip loading the object which contains the profiling runtime's
372372
static initializer.
@@ -380,7 +380,7 @@ without using static initializers, do this manually:
380380
to ``__llvm_profile_write_file``.
381381

382382
* Forward-declare ``int __llvm_profile_write_file(void)`` and call it to write
383-
out a profile. This function returns 0 when it succeeds, and a non-zero value
383+
out a profile. This function returns 0 on success, and a non-zero value
384384
otherwise. Calling this function multiple times appends profile data to an
385385
existing on-disk raw profile.
386386

@@ -418,7 +418,7 @@ Collecting coverage reports for the llvm project
418418
================================================
419419

420420
To prepare a coverage report for llvm (and any of its sub-projects), add
421-
``-DLLVM_BUILD_INSTRUMENTED_COVERAGE=On`` to the cmake configuration. Raw
421+
``-DLLVM_BUILD_INSTRUMENTED_COVERAGE=On`` to the CMake configuration. Raw
422422
profiles will be written to ``$BUILD_DIR/profiles/``. To prepare an html
423423
report, run ``llvm/utils/prepare-code-coverage-artifact.py``.
424424

@@ -429,7 +429,7 @@ To specify an alternate directory for raw profiles, use
429429
Drawbacks and limitations
430430
=========================
431431

432-
* Prior to version 2.26, the GNU binutils BFD linker is not able link programs
432+
* Prior to version 2.26, the GNU binutils BFD linker cannot link programs
433433
compiled with ``-fcoverage-mapping`` in its ``--gc-sections`` mode. Possible
434434
workarounds include disabling ``--gc-sections``, upgrading to a newer version
435435
of BFD, or using the Gold linker.

clang/include/clang/Analysis/Analyses/LifetimeSafety.h

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,35 @@
1919
#define LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_H
2020
#include "clang/Analysis/AnalysisDeclContext.h"
2121
#include "clang/Analysis/CFG.h"
22+
#include "clang/Basic/SourceLocation.h"
23+
#include "llvm/ADT/DenseMapInfo.h"
24+
#include "llvm/ADT/ImmutableMap.h"
2225
#include "llvm/ADT/ImmutableSet.h"
2326
#include "llvm/ADT/StringMap.h"
2427
#include <memory>
2528

2629
namespace clang::lifetimes {
2730

31+
/// Enum to track the confidence level of a potential error.
32+
enum class Confidence {
33+
None,
34+
Maybe, // Reported as a potential error (-Wlifetime-safety-strict)
35+
Definite // Reported as a definite error (-Wlifetime-safety-permissive)
36+
};
37+
38+
class LifetimeSafetyReporter {
39+
public:
40+
LifetimeSafetyReporter() = default;
41+
virtual ~LifetimeSafetyReporter() = default;
42+
43+
virtual void reportUseAfterFree(const Expr *IssueExpr, const Expr *UseExpr,
44+
SourceLocation FreeLoc,
45+
Confidence Confidence) {}
46+
};
47+
2848
/// The main entry point for the analysis.
29-
void runLifetimeSafetyAnalysis(AnalysisDeclContext &AC);
49+
void runLifetimeSafetyAnalysis(AnalysisDeclContext &AC,
50+
LifetimeSafetyReporter *Reporter);
3051

3152
namespace internal {
3253
// Forward declarations of internal types.
@@ -53,6 +74,7 @@ template <typename Tag> struct ID {
5374
IDBuilder.AddInteger(Value);
5475
}
5576
};
77+
5678
template <typename Tag>
5779
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, ID<Tag> ID) {
5880
return OS << ID.Value;
@@ -78,7 +100,8 @@ using ProgramPoint = const Fact *;
78100
/// encapsulates the various dataflow analyses.
79101
class LifetimeSafetyAnalysis {
80102
public:
81-
LifetimeSafetyAnalysis(AnalysisDeclContext &AC);
103+
LifetimeSafetyAnalysis(AnalysisDeclContext &AC,
104+
LifetimeSafetyReporter *Reporter);
82105
~LifetimeSafetyAnalysis();
83106

84107
void run();
@@ -87,7 +110,7 @@ class LifetimeSafetyAnalysis {
87110
LoanSet getLoansAtPoint(OriginID OID, ProgramPoint PP) const;
88111

89112
/// Returns the set of loans that have expired at a specific program point.
90-
LoanSet getExpiredLoansAtPoint(ProgramPoint PP) const;
113+
std::vector<LoanID> getExpiredLoansAtPoint(ProgramPoint PP) const;
91114

92115
/// Finds the OriginID for a given declaration.
93116
/// Returns a null optional if not found.
@@ -110,6 +133,7 @@ class LifetimeSafetyAnalysis {
110133

111134
private:
112135
AnalysisDeclContext &AC;
136+
LifetimeSafetyReporter *Reporter;
113137
std::unique_ptr<LifetimeFactory> Factory;
114138
std::unique_ptr<FactManager> FactMgr;
115139
std::unique_ptr<LoanPropagationAnalysis> LoanPropagation;
@@ -118,4 +142,25 @@ class LifetimeSafetyAnalysis {
118142
} // namespace internal
119143
} // namespace clang::lifetimes
120144

145+
namespace llvm {
146+
template <typename Tag>
147+
struct DenseMapInfo<clang::lifetimes::internal::ID<Tag>> {
148+
using ID = clang::lifetimes::internal::ID<Tag>;
149+
150+
static inline ID getEmptyKey() {
151+
return {DenseMapInfo<uint32_t>::getEmptyKey()};
152+
}
153+
154+
static inline ID getTombstoneKey() {
155+
return {DenseMapInfo<uint32_t>::getTombstoneKey()};
156+
}
157+
158+
static unsigned getHashValue(const ID &Val) {
159+
return DenseMapInfo<uint32_t>::getHashValue(Val.Value);
160+
}
161+
162+
static bool isEqual(const ID &LHS, const ID &RHS) { return LHS == RHS; }
163+
};
164+
} // namespace llvm
165+
121166
#endif // LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_H

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,14 @@ def Dangling : DiagGroup<"dangling", [DanglingAssignment,
533533
DanglingGsl,
534534
ReturnStackAddress]>;
535535

536-
def LifetimeSafety : DiagGroup<"experimental-lifetime-safety">;
536+
def LifetimeSafetyPermissive : DiagGroup<"experimental-lifetime-safety-permissive">;
537+
def LifetimeSafetyStrict : DiagGroup<"experimental-lifetime-safety-strict">;
538+
def LifetimeSafety : DiagGroup<"experimental-lifetime-safety",
539+
[LifetimeSafetyPermissive, LifetimeSafetyStrict]> {
540+
code Documentation = [{
541+
Experimental warnings to detect use-after-free and related temporal safety bugs based on lifetime safety analysis.
542+
}];
543+
}
537544

538545
def DistributedObjectModifiers : DiagGroup<"distributed-object-modifiers">;
539546
def DllexportExplicitInstantiationDecl : DiagGroup<"dllexport-explicit-instantiation-decl">;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10667,9 +10667,15 @@ def warn_dangling_reference_captured_by_unknown : Warning<
1066710667
"object whose reference is captured will be destroyed at the end of "
1066810668
"the full-expression">, InGroup<DanglingCapture>;
1066910669

10670-
def warn_experimental_lifetime_safety_dummy_warning : Warning<
10671-
"todo: remove this warning after we have atleast one warning based on the lifetime analysis">,
10672-
InGroup<LifetimeSafety>, DefaultIgnore;
10670+
// Diagnostics based on the Lifetime safety analysis.
10671+
def warn_lifetime_safety_loan_expires_permissive : Warning<
10672+
"object whose reference is captured does not live long enough">,
10673+
InGroup<LifetimeSafetyPermissive>, DefaultIgnore;
10674+
def warn_lifetime_safety_loan_expires_strict : Warning<
10675+
"object whose reference is captured may not live long enough">,
10676+
InGroup<LifetimeSafetyStrict>, DefaultIgnore;
10677+
def note_lifetime_safety_used_here : Note<"later used here">;
10678+
def note_lifetime_safety_destroyed_here : Note<"destroyed here">;
1067310679

1067410680
// For non-floating point, expressions of the form x == x or x != x
1067510681
// should result in a warning, since these always evaluate to a constant.

0 commit comments

Comments
 (0)