Skip to content

Commit de02937

Browse files
committed
merge main into amd-staging
reverts: [ctx_prof] CtxProfAnalysis: populate module data (llvm#102930) Change-Id: I10d0d424f5fe93ab97f3753825ce33346898f6f4
2 parents 5b8bf76 + 13a6a79 commit de02937

File tree

295 files changed

+8542
-2594
lines changed

Some content is hidden

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

295 files changed

+8542
-2594
lines changed

clang-tools-extra/include-cleaner/lib/WalkAST.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,13 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
271271
// specialized template. Implicit ones are filtered out by RAV.
272272
bool
273273
VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *CTSD) {
274-
// if (CTSD->isExplicitSpecialization())
275274
if (clang::isTemplateExplicitInstantiationOrSpecialization(
276275
CTSD->getTemplateSpecializationKind()))
277276
report(CTSD->getLocation(),
278277
CTSD->getSpecializedTemplate()->getTemplatedDecl());
279278
return true;
280279
}
281280
bool VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *VTSD) {
282-
// if (VTSD->isExplicitSpecialization())
283281
if (clang::isTemplateExplicitInstantiationOrSpecialization(
284282
VTSD->getTemplateSpecializationKind()))
285283
report(VTSD->getLocation(),

clang/docs/ReleaseNotes.rst

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,31 @@ C++ Specific Potentially Breaking Changes
4949
few users and can be written as ``__is_same(__remove_cv(T), decltype(nullptr))``,
5050
which GCC supports as well.
5151

52+
- Clang will now correctly diagnose as ill-formed a constant expression where an
53+
enum without a fixed underlying type is set to a value outside the range of
54+
the enumeration's values.
55+
56+
.. code-block:: c++
57+
58+
enum E { Zero, One, Two, Three, Four };
59+
constexpr E Val1 = (E)3; // Ok
60+
constexpr E Val2 = (E)7; // Ok
61+
constexpr E Val3 = (E)8; // Now ill-formed, out of the range [0, 7]
62+
constexpr E Val4 = (E)-1; // Now ill-formed, out of the range [0, 7]
63+
64+
Since Clang 16, it has been possible to suppress the diagnostic via
65+
`-Wno-enum-constexpr-conversion`, to allow for a transition period for users.
66+
Now, in Clang 20, **it is no longer possible to suppress the diagnostic**.
67+
68+
- Extraneous template headers are now ill-formed by default.
69+
This error can be disable with ``-Wno-error=extraneous-template-head``.
70+
71+
.. code-block:: c++
72+
73+
template <> // error: extraneous template head
74+
template <typename T>
75+
void f();
76+
5277
ABI Changes in This Version
5378
---------------------------
5479

@@ -148,6 +173,11 @@ Modified Compiler Flags
148173
Removed Compiler Flags
149174
-------------------------
150175

176+
- The compiler flag `-Wenum-constexpr-conversion` (and the `Wno-`, `Wno-error-`
177+
derivatives) is now removed, since it's no longer possible to suppress the
178+
diagnostic (see above). Users can expect an `unknown warning` diagnostic if
179+
it's still in use.
180+
151181
Attribute Changes in Clang
152182
--------------------------
153183

@@ -367,6 +397,36 @@ Moved checkers
367397
Sanitizers
368398
----------
369399

400+
- Added the ``-fsanitize-overflow-pattern-exclusion=`` flag which can be used
401+
to disable specific overflow-dependent code patterns. The supported patterns
402+
are: ``add-overflow-test``, ``negated-unsigned-const``, and
403+
``post-decr-while``. The sanitizer instrumentation can be toggled off for all
404+
available patterns by specifying ``all``. Conversely, you can disable all
405+
exclusions with ``none``.
406+
407+
.. code-block:: c++
408+
409+
/// specified with ``-fsanitize-overflow-pattern-exclusion=add-overflow-test``
410+
int common_overflow_check_pattern(unsigned base, unsigned offset) {
411+
if (base + offset < base) { /* ... */ } // The pattern of `a + b < a`, and other re-orderings, won't be instrumented
412+
}
413+
414+
/// specified with ``-fsanitize-overflow-pattern-exclusion=negated-unsigned-const``
415+
void negation_overflow() {
416+
unsigned long foo = -1UL; // No longer causes a negation overflow warning
417+
unsigned long bar = -2UL; // and so on...
418+
}
419+
420+
/// specified with ``-fsanitize-overflow-pattern-exclusion=post-decr-while``
421+
void while_post_decrement() {
422+
unsigned char count = 16;
423+
while (count--) { /* ... */} // No longer causes unsigned-integer-overflow sanitizer to trip
424+
}
425+
426+
Many existing projects have a large amount of these code patterns present.
427+
This new flag should allow those projects to enable integer sanitizers with
428+
less noise.
429+
370430
Python Binding Changes
371431
----------------------
372432
- Fixed an issue that led to crashes when calling ``Type.get_exception_specification_kind``.

clang/docs/UndefinedBehaviorSanitizer.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,48 @@ To silence reports from unsigned integer overflow, you can set
293293
``-fsanitize-recover=unsigned-integer-overflow``, is particularly useful for
294294
providing fuzzing signal without blowing up logs.
295295

296+
Disabling instrumentation for common overflow patterns
297+
------------------------------------------------------
298+
299+
There are certain overflow-dependent or overflow-prone code patterns which
300+
produce a lot of noise for integer overflow/truncation sanitizers. Negated
301+
unsigned constants, post-decrements in a while loop condition and simple
302+
overflow checks are accepted and pervasive code patterns. However, the signal
303+
received from sanitizers instrumenting these code patterns may be too noisy for
304+
some projects. To disable instrumentation for these common patterns one should
305+
use ``-fsanitize-overflow-pattern-exclusion=``.
306+
307+
Currently, this option supports three overflow-dependent code idioms:
308+
309+
``negated-unsigned-const``
310+
311+
.. code-block:: c++
312+
313+
/// -fsanitize-overflow-pattern-exclusion=negated-unsigned-const
314+
unsigned long foo = -1UL; // No longer causes a negation overflow warning
315+
unsigned long bar = -2UL; // and so on...
316+
317+
``post-decr-while``
318+
319+
.. code-block:: c++
320+
321+
/// -fsanitize-overflow-pattern-exclusion=post-decr-while
322+
unsigned char count = 16;
323+
while (count--) { /* ... */ } // No longer causes unsigned-integer-overflow sanitizer to trip
324+
325+
``add-overflow-test``
326+
327+
.. code-block:: c++
328+
329+
/// -fsanitize-overflow-pattern-exclusion=add-overflow-test
330+
if (base + offset < base) { /* ... */ } // The pattern of `a + b < a`, and other re-orderings,
331+
// won't be instrumented (same for signed types)
332+
333+
You can enable all exclusions with
334+
``-fsanitize-overflow-pattern-exclusion=all`` or disable all exclusions with
335+
``-fsanitize-overflow-pattern-exclusion=none``. Specifying ``none`` has
336+
precedence over other values.
337+
296338
Issue Suppression
297339
=================
298340

clang/include/clang/AST/Availability.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ struct AvailabilityInfo {
9797
return UnconditionallyUnavailable;
9898
}
9999

100+
/// Augments the existing information with additional constraints provided by
101+
/// \c Other.
102+
void mergeWith(AvailabilityInfo Other);
103+
100104
AvailabilityInfo(StringRef Domain, VersionTuple I, VersionTuple D,
101105
VersionTuple O, bool U, bool UD, bool UU)
102106
: Domain(Domain), Introduced(I), Deprecated(D), Obsoleted(O),

clang/include/clang/AST/Decl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3206,6 +3206,10 @@ class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
32063206
/// Set the C++11 in-class initializer for this member.
32073207
void setInClassInitializer(Expr *NewInit);
32083208

3209+
/// Find the FieldDecl specified in a FAM's "counted_by" attribute. Returns
3210+
/// \p nullptr if either the attribute or the field doesn't exist.
3211+
const FieldDecl *findCountedByField() const;
3212+
32093213
private:
32103214
void setLazyInClassInitializer(LazyDeclStmtPtr NewInit);
32113215

clang/include/clang/AST/Expr.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4043,6 +4043,15 @@ class BinaryOperator : public Expr {
40434043
void setHasStoredFPFeatures(bool B) { BinaryOperatorBits.HasFPFeatures = B; }
40444044
bool hasStoredFPFeatures() const { return BinaryOperatorBits.HasFPFeatures; }
40454045

4046+
/// Set and get the bit that informs arithmetic overflow sanitizers whether
4047+
/// or not they should exclude certain BinaryOperators from instrumentation
4048+
void setExcludedOverflowPattern(bool B) {
4049+
BinaryOperatorBits.ExcludedOverflowPattern = B;
4050+
}
4051+
bool hasExcludedOverflowPattern() const {
4052+
return BinaryOperatorBits.ExcludedOverflowPattern;
4053+
}
4054+
40464055
/// Get FPFeatures from trailing storage
40474056
FPOptionsOverride getStoredFPFeatures() const {
40484057
assert(hasStoredFPFeatures());

clang/include/clang/AST/Stmt.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,11 @@ class alignas(void *) Stmt {
650650
LLVM_PREFERRED_TYPE(bool)
651651
unsigned HasFPFeatures : 1;
652652

653+
/// Whether or not this BinaryOperator should be excluded from integer
654+
/// overflow sanitization.
655+
LLVM_PREFERRED_TYPE(bool)
656+
unsigned ExcludedOverflowPattern : 1;
657+
653658
SourceLocation OpLoc;
654659
};
655660

clang/include/clang/Basic/DiagnosticASTKinds.td

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,9 @@ def warn_integer_constant_overflow : Warning<
394394
def warn_fixedpoint_constant_overflow : Warning<
395395
"overflow in expression; result is %0 with type %1">,
396396
InGroup<DiagGroup<"fixed-point-overflow">>;
397-
def warn_constexpr_unscoped_enum_out_of_range : Warning<
397+
def note_constexpr_unscoped_enum_out_of_range : Note<
398398
"integer value %0 is outside the valid range of values [%1, %2] for the "
399-
"enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,
400-
InGroup<DiagGroup<"enum-constexpr-conversion">>;
399+
"enumeration type %3">;
401400

402401
// This is a temporary diagnostic, and shall be removed once our
403402
// implementation is complete, and like the preceding constexpr notes belongs

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5431,7 +5431,8 @@ def err_template_spec_extra_headers : Error<
54315431
"extraneous template parameter list in template specialization or "
54325432
"out-of-line template definition">;
54335433
def ext_template_spec_extra_headers : ExtWarn<
5434-
"extraneous template parameter list in template specialization">;
5434+
"extraneous template parameter list in template specialization">,
5435+
InGroup<DiagGroup<"extraneous-template-head">>, DefaultError;
54355436
def note_explicit_template_spec_does_not_need_header : Note<
54365437
"'template<>' header not required for explicitly-specialized class %0 "
54375438
"declared here">;

clang/include/clang/Basic/LangOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ VALUE_LANGOPT(TrivialAutoVarInitMaxSize, 32, 0,
416416
"stop trivial automatic variable initialization if var size exceeds the specified size (in bytes). Must be greater than 0.")
417417
ENUM_LANGOPT(SignedOverflowBehavior, SignedOverflowBehaviorTy, 2, SOB_Undefined,
418418
"signed integer overflow handling")
419+
LANGOPT(IgnoreNegationOverflow, 1, 0, "ignore overflow caused by negation")
420+
LANGOPT(SanitizeOverflowIdioms, 1, 1, "enable instrumentation for common overflow idioms")
419421
ENUM_LANGOPT(ThreadModel , ThreadModelKind, 2, ThreadModelKind::POSIX, "Thread Model")
420422

421423
BENIGN_LANGOPT(ArrowDepth, 32, 256,

clang/include/clang/Basic/LangOptions.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,21 @@ class LangOptionsBase {
367367
PerThread,
368368
};
369369

370+
/// Exclude certain code patterns from being instrumented by arithmetic
371+
/// overflow sanitizers
372+
enum OverflowPatternExclusionKind {
373+
/// Don't exclude any overflow patterns from sanitizers
374+
None = 1 << 0,
375+
/// Exclude all overflow patterns (below)
376+
All = 1 << 1,
377+
/// if (a + b < a)
378+
AddOverflowTest = 1 << 2,
379+
/// -1UL
380+
NegUnsignedConst = 1 << 3,
381+
/// while (count--)
382+
PostDecrInWhile = 1 << 4,
383+
};
384+
370385
enum class DefaultVisiblityExportMapping {
371386
None,
372387
/// map only explicit default visibilities to exported
@@ -555,6 +570,11 @@ class LangOptions : public LangOptionsBase {
555570
/// The default stream kind used for HIP kernel launching.
556571
GPUDefaultStreamKind GPUDefaultStream;
557572

573+
/// Which overflow patterns should be excluded from sanitizer instrumentation
574+
unsigned OverflowPatternExclusionMask = 0;
575+
576+
std::vector<std::string> OverflowPatternExclusionValues;
577+
558578
/// The seed used by the randomize structure layout feature.
559579
std::string RandstructSeed;
560580

@@ -630,6 +650,14 @@ class LangOptions : public LangOptionsBase {
630650
return MSCompatibilityVersion >= MajorVersion * 100000U;
631651
}
632652

653+
bool isOverflowPatternExcluded(OverflowPatternExclusionKind Kind) const {
654+
if (OverflowPatternExclusionMask & OverflowPatternExclusionKind::None)
655+
return false;
656+
if (OverflowPatternExclusionMask & OverflowPatternExclusionKind::All)
657+
return true;
658+
return OverflowPatternExclusionMask & Kind;
659+
}
660+
633661
/// Reset all of the options that are not considered when building a
634662
/// module.
635663
void resetNonModularOptions();

clang/include/clang/Driver/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,6 +2570,11 @@ defm sanitize_stats : BoolOption<"f", "sanitize-stats",
25702570
"Disable">,
25712571
BothFlags<[], [ClangOption], " sanitizer statistics gathering.">>,
25722572
Group<f_clang_Group>;
2573+
def fsanitize_overflow_pattern_exclusion_EQ : CommaJoined<["-"], "fsanitize-overflow-pattern-exclusion=">,
2574+
HelpText<"Specify the overflow patterns to exclude from artihmetic sanitizer instrumentation">,
2575+
Visibility<[ClangOption, CC1Option]>,
2576+
Values<"none,all,add-overflow-test,negated-unsigned-const,post-decr-while">,
2577+
MarshallingInfoStringVector<LangOpts<"OverflowPatternExclusionValues">>;
25732578
def fsanitize_thread_memory_access : Flag<["-"], "fsanitize-thread-memory-access">,
25742579
Group<f_clang_Group>,
25752580
HelpText<"Enable memory access instrumentation in ThreadSanitizer (default)">;

clang/include/clang/Driver/SanitizerArgs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class SanitizerArgs {
3333
std::vector<std::string> BinaryMetadataIgnorelistFiles;
3434
int CoverageFeatures = 0;
3535
int BinaryMetadataFeatures = 0;
36+
int OverflowPatternExclusions = 0;
3637
int MsanTrackOrigins = 0;
3738
bool MsanUseAfterDtor = true;
3839
bool MsanParamRetval = true;

0 commit comments

Comments
 (0)