Skip to content

Commit 6d13e32

Browse files
committed
Merge branch 'main' into clang-pointer-auth-basic-declarations
2 parents df81082 + 693a458 commit 6d13e32

File tree

649 files changed

+15296
-7423
lines changed

Some content is hidden

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

649 files changed

+15296
-7423
lines changed

bolt/include/bolt/Rewrite/RewriteInstance.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,6 @@ class RewriteInstance {
368368
/// rewritten binary.
369369
void patchBuildID();
370370

371-
/// Return file offset corresponding to a given virtual address.
372-
uint64_t getFileOffsetFor(uint64_t Address) {
373-
assert(Address >= NewTextSegmentAddress &&
374-
"address in not in the new text segment");
375-
return Address - NewTextSegmentAddress + NewTextSegmentOffset;
376-
}
377-
378371
/// Return file offset corresponding to a virtual \p Address.
379372
/// Return 0 if the address has no mapping in the file, including being
380373
/// part of .bss section.
@@ -398,9 +391,6 @@ class RewriteInstance {
398391
/// Return true if the section holds debug information.
399392
static bool isDebugSection(StringRef SectionName);
400393

401-
/// Return true if the section holds linux kernel symbol information.
402-
static bool isKSymtabSection(StringRef SectionName);
403-
404394
/// Adds Debug section to overwrite.
405395
static void addToDebugSectionsToOverwrite(const char *Section) {
406396
DebugSectionsToOverwrite.emplace_back(Section);

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5767,10 +5767,3 @@ bool RewriteInstance::isDebugSection(StringRef SectionName) {
57675767

57685768
return false;
57695769
}
5770-
5771-
bool RewriteInstance::isKSymtabSection(StringRef SectionName) {
5772-
if (SectionName.starts_with("__ksymtab"))
5773-
return true;
5774-
5775-
return false;
5776-
}

clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ void UnnecessaryValueParamCheck::check(const MatchFinder::MatchResult &Result) {
8585

8686
TraversalKindScope RAII(*Result.Context, TK_AsIs);
8787

88-
FunctionParmMutationAnalyzer &Analyzer =
89-
MutationAnalyzers.try_emplace(Function, *Function, *Result.Context)
90-
.first->second;
91-
if (Analyzer.isMutated(Param))
88+
FunctionParmMutationAnalyzer *Analyzer =
89+
FunctionParmMutationAnalyzer::getFunctionParmMutationAnalyzer(
90+
*Function, *Result.Context, MutationAnalyzerCache);
91+
if (Analyzer->isMutated(Param))
9292
return;
9393

9494
const bool IsConstQualified =
@@ -169,7 +169,7 @@ void UnnecessaryValueParamCheck::storeOptions(
169169
}
170170

171171
void UnnecessaryValueParamCheck::onEndOfTranslationUnit() {
172-
MutationAnalyzers.clear();
172+
MutationAnalyzerCache.clear();
173173
}
174174

175175
void UnnecessaryValueParamCheck::handleMoveFix(const ParmVarDecl &Var,

clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ class UnnecessaryValueParamCheck : public ClangTidyCheck {
3737
void handleMoveFix(const ParmVarDecl &Var, const DeclRefExpr &CopyArgument,
3838
const ASTContext &Context);
3939

40-
llvm::DenseMap<const FunctionDecl *, FunctionParmMutationAnalyzer>
41-
MutationAnalyzers;
40+
ExprMutationAnalyzer::Memoized MutationAnalyzerCache;
4241
utils::IncludeInserter Inserter;
4342
const std::vector<StringRef> AllowedTypes;
4443
};

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ Changes in existing checks
221221
<clang-tidy/checks/llvm/header-guard>` check by replacing the local
222222
option `HeaderFileExtensions` by the global option of the same name.
223223

224+
- Improved :doc:`misc-const-correctness
225+
<clang-tidy/checks/misc/const-correctness>` check by avoiding infinite recursion
226+
for recursive forwarding reference.
227+
224228
- Improved :doc:`misc-definitions-in-headers
225229
<clang-tidy/checks/misc/definitions-in-headers>` check by replacing the local
226230
option `HeaderFileExtensions` by the global option of the same name.

clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,6 @@ Options
190190

191191
.. option:: WarnOnSizeOfPointerToAggregate
192192

193-
When `true, the check will warn on an expression like
193+
When `true`, the check will warn on an expression like
194194
``sizeof(expr)`` where the expression is a pointer
195195
to aggregate. Default is `true`.

clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,18 @@ void concatenate3(Args... args)
5858
(..., (stream << args));
5959
}
6060
} // namespace gh70323
61+
62+
namespace gh60895 {
63+
64+
template <class T> void f1(T &&a);
65+
template <class T> void f2(T &&a);
66+
template <class T> void f1(T &&a) { f2<T>(a); }
67+
template <class T> void f2(T &&a) { f1<T>(a); }
68+
void f() {
69+
int x = 0;
70+
// CHECK-MESSAGES:[[@LINE-1]]:3: warning: variable 'x' of type 'int' can be declared 'const'
71+
// CHECK-FIXES: int const x = 0;
72+
f1(x);
73+
}
74+
75+
} // namespace gh60895

clang/docs/LanguageExtensions.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3466,6 +3466,54 @@ Query for this feature with ``__has_builtin(__builtin_trap)``.
34663466
34673467
``__builtin_arm_trap`` is lowered to the ``llvm.aarch64.break`` builtin, and then to ``brk #payload``.
34683468
3469+
``__builtin_allow_runtime_check``
3470+
---------------------------------
3471+
3472+
``__builtin_allow_runtime_check`` return true if the check at the current
3473+
program location should be executed. It is expected to be used to implement
3474+
``assert`` like checks which can be safely removed by optimizer.
3475+
3476+
**Syntax**:
3477+
3478+
.. code-block:: c++
3479+
3480+
bool __builtin_allow_runtime_check(const char* kind)
3481+
3482+
**Example of use**:
3483+
3484+
.. code-block:: c++
3485+
3486+
if (__builtin_allow_runtime_check("mycheck") && !ExpensiveCheck()) {
3487+
abort();
3488+
}
3489+
3490+
**Description**
3491+
3492+
``__builtin_allow_runtime_check`` is lowered to ` ``llvm.allow.runtime.check``
3493+
<https://llvm.org/docs/LangRef.html#llvm-allow-runtime-check-intrinsic>`_
3494+
builtin.
3495+
3496+
The ``__builtin_allow_runtime_check()`` is expected to be used with control
3497+
flow conditions such as in ``if`` to guard expensive runtime checks. The
3498+
specific rules for selecting permitted checks can differ and are controlled by
3499+
the compiler options.
3500+
3501+
Flags to control checks:
3502+
* ``-mllvm -lower-allow-check-percentile-cutoff-hot=N`` where N is PGO hotness
3503+
cutoff in range ``[0, 999999]`` to disallow checks in hot code.
3504+
* ``-mllvm -lower-allow-check-random-rate=P`` where P is number in range
3505+
``[0.0, 1.0]`` representation probability of keeping a check.
3506+
* If both flags are specified, ``-lower-allow-check-random-rate`` takes
3507+
precedence.
3508+
* If none is specified, ``__builtin_allow_runtime_check`` is lowered as
3509+
``true``, allowing all checks.
3510+
3511+
Parameter ``kind`` is a string literal representing a user selected kind for
3512+
guarded check. It's unused now. It will enable kind-specific lowering in future.
3513+
E.g. a higher hotness cutoff can be used for more expensive kind of check.
3514+
3515+
Query for this feature with ``__has_builtin(__builtin_allow_runtime_check)``.
3516+
34693517
``__builtin_nondeterministic_value``
34703518
------------------------------------
34713519

clang/docs/ReleaseNotes.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ AST Dumping Potentially Breaking Changes
6868

6969
Clang Frontend Potentially Breaking Changes
7070
-------------------------------------------
71-
- Removed support for constructing on-stack ``TemplateArgumentList``s; interfaces should instead
71+
- Removed support for constructing on-stack ``TemplateArgumentList``\ s; interfaces should instead
7272
use ``ArrayRef<TemplateArgument>`` to pass template arguments. Transitioning internal uses to
7373
``ArrayRef<TemplateArgument>`` reduces AST memory usage by 0.4% when compiling clang, and is
7474
expected to show similar improvements on other workloads.
@@ -214,6 +214,9 @@ New Compiler Flags
214214
This diagnostic can be disabled to make ``-Wmissing-field-initializers`` behave
215215
like it did before Clang 18.x. Fixes #GH56628
216216

217+
- ``-fexperimental-modules-reduced-bmi`` enables the Reduced BMI for C++20 named modules.
218+
See the document of standard C++ modules for details.
219+
217220
Deprecated Compiler Flags
218221
-------------------------
219222

@@ -361,6 +364,8 @@ Improvements to Clang's diagnostics
361364
- Clang now uses the correct type-parameter-key (``class`` or ``typename``) when printing
362365
template template parameter declarations.
363366

367+
- Clang now diagnoses requires expressions with explicit object parameters.
368+
364369
Improvements to Clang's time-trace
365370
----------------------------------
366371

@@ -531,7 +536,6 @@ Bug Fixes to C++ Support
531536
Fixes (#GH70604), (#GH79754), (#GH84163), (#GH84425), (#GH86054), (#GH86398), and (#GH86399).
532537
- Fix a crash when deducing ``auto`` from an invalid dereference (#GH88329).
533538
- Fix a crash in requires expression with templated base class member function. Fixes (#GH84020).
534-
- Placement new initializes typedef array with correct size (#GH41441)
535539

536540
Bug Fixes to AST Handling
537541
^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -676,6 +680,8 @@ Static Analyzer
676680
but not under any case blocks if ``unroll-loops=true`` analyzer config is
677681
set. (#GH68819)
678682
- Support C++23 static operator calls. (#GH84972)
683+
- Fixed a crash in ``security.cert.env.InvalidPtr`` checker when accidentally
684+
matched user-defined ``strerror`` and similar library functions. (GH#88181)
679685

680686
New features
681687
^^^^^^^^^^^^

clang/docs/StandardCPlusPlusModules.rst

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,112 @@ is attached to the global module fragments. For example:
520520

521521
Now the linkage name of ``NS::foo()`` will be ``_ZN2NS3fooEv``.
522522

523+
Reduced BMI
524+
-----------
525+
526+
To support the 2 phase compilation model, Clang chose to put everything needed to
527+
produce an object into the BMI. But every consumer of the BMI, except itself, doesn't
528+
need such informations. It makes the BMI to larger and so may introduce unnecessary
529+
dependencies into the BMI. To mitigate the problem, we decided to reduce the information
530+
contained in the BMI.
531+
532+
To be clear, we call the default BMI as Full BMI and the new introduced BMI as Reduced
533+
BMI.
534+
535+
Users can use ``-fexperimental-modules-reduced-bmi`` flag to enable the Reduced BMI.
536+
537+
For one phase compilation model (CMake implements this model), with
538+
``-fexperimental-modules-reduced-bmi``, the generated BMI will be Reduced BMI automatically.
539+
(The output path of the BMI is specified by ``-fmodule-output=`` as usual one phase
540+
compilation model).
541+
542+
It is still possible to support Reduced BMI in two phase compilation model. With
543+
``-fexperimental-modules-reduced-bmi``, ``--precompile`` and ``-fmodule-output=`` specified,
544+
the generated BMI specified by ``-o`` will be full BMI and the BMI specified by
545+
``-fmodule-output=`` will be Reduced BMI. The dependency graph may be:
546+
547+
.. code-block:: none
548+
549+
module-unit.cppm --> module-unit.full.pcm -> module-unit.o
550+
|
551+
-> module-unit.reduced.pcm -> consumer1.cpp
552+
-> consumer2.cpp
553+
-> ...
554+
-> consumer_n.cpp
555+
556+
We don't emit diagnostics if ``-fexperimental-modules-reduced-bmi`` is used with a non-module
557+
unit. This design helps the end users of one phase compilation model to perform experiments
558+
early without asking for the help of build systems. The users of build systems which supports
559+
two phase compilation model still need helps from build systems.
560+
561+
Within Reduced BMI, we won't write unreachable entities from GMF, definitions of non-inline
562+
functions and non-inline variables. This may not be a transparent change.
563+
`[module.global.frag]ex2 <https://eel.is/c++draft/module.global.frag#example-2>`_ may be a good
564+
example:
565+
566+
.. code-block:: c++
567+
568+
// foo.h
569+
namespace N {
570+
struct X {};
571+
int d();
572+
int e();
573+
inline int f(X, int = d()) { return e(); }
574+
int g(X);
575+
int h(X);
576+
}
577+
578+
// M.cppm
579+
module;
580+
#include "foo.h"
581+
export module M;
582+
template<typename T> int use_f() {
583+
N::X x; // N::X, N, and :: are decl-reachable from use_f
584+
return f(x, 123); // N::f is decl-reachable from use_f,
585+
// N::e is indirectly decl-reachable from use_f
586+
// because it is decl-reachable from N::f, and
587+
// N::d is decl-reachable from use_f
588+
// because it is decl-reachable from N::f
589+
// even though it is not used in this call
590+
}
591+
template<typename T> int use_g() {
592+
N::X x; // N::X, N, and :: are decl-reachable from use_g
593+
return g((T(), x)); // N::g is not decl-reachable from use_g
594+
}
595+
template<typename T> int use_h() {
596+
N::X x; // N::X, N, and :: are decl-reachable from use_h
597+
return h((T(), x)); // N::h is not decl-reachable from use_h, but
598+
// N::h is decl-reachable from use_h<int>
599+
}
600+
int k = use_h<int>();
601+
// use_h<int> is decl-reachable from k, so
602+
// N::h is decl-reachable from k
603+
604+
// M-impl.cpp
605+
module M;
606+
int a = use_f<int>(); // OK
607+
int b = use_g<int>(); // error: no viable function for call to g;
608+
// g is not decl-reachable from purview of
609+
// module M's interface, so is discarded
610+
int c = use_h<int>(); // OK
611+
612+
In the above example, the function definition of ``N::g`` is elided from the Reduced
613+
BMI of ``M.cppm``. Then the use of ``use_g<int>`` in ``M-impl.cpp`` fails
614+
to instantiate. For such issues, users can add references to ``N::g`` in the module purview
615+
of ``M.cppm`` to make sure it is reachable, e.g., ``using N::g;``.
616+
617+
We think the Reduced BMI is the correct direction. But given it is a drastic change,
618+
we'd like to make it experimental first to avoid breaking existing users. The roadmap
619+
of Reduced BMI may be:
620+
621+
1. ``-fexperimental-modules-reduced-bmi`` is opt in for 1~2 releases. The period depends
622+
on testing feedbacks.
623+
2. We would announce Reduced BMI is not experimental and introduce ``-fmodules-reduced-bmi``.
624+
and suggest users to enable this mode. This may takes 1~2 releases too.
625+
3. Finally we will enable this by default. When that time comes, the term BMI will refer to
626+
the reduced BMI today and the Full BMI will only be meaningful to build systems which
627+
loves to support two phase compilations.
628+
523629
Performance Tips
524630
----------------
525631

clang/docs/tools/clang-formatted-files.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ clang/include/clang/Analysis/Analyses/CalledOnceCheck.h
123123
clang/include/clang/Analysis/Analyses/CFGReachabilityAnalysis.h
124124
clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
125125
clang/include/clang/Analysis/FlowSensitive/AdornedCFG.h
126+
clang/include/clang/Analysis/FlowSensitive/ASTOps.h
126127
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
127128
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
128129
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -307,6 +308,7 @@ clang/lib/Analysis/CalledOnceCheck.cpp
307308
clang/lib/Analysis/CloneDetection.cpp
308309
clang/lib/Analysis/CodeInjector.cpp
309310
clang/lib/Analysis/FlowSensitive/AdornedCFG.cpp
311+
clang/lib/Analysis/FlowSensitive/ASTOps.cpp
310312
clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
311313
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
312314
clang/lib/Analysis/FlowSensitive/DebugSupport.cpp

0 commit comments

Comments
 (0)