Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
996639d
[MLIR][BufferResultsToOutParamsPass] Add Option to Modify Public Func…
veera-sivarajan Nov 10, 2025
a8a0ffb
[clang][bytecode] Check source pointer for bitcast validity (#166907)
tbaederr Nov 10, 2025
d10a851
[WebAssembly] Implement more of getCastInstrCost (#164612)
sparker-arm Nov 10, 2025
f613801
[RISCV][llvm] Support Smpmpmt version 0.6 (#166322)
4vtomat Nov 10, 2025
6408703
[Polly] Retain vectorization for fallback loop when RTC is unsatisfia…
kartcq Nov 10, 2025
4b433cb
[clang-tidy] Rename 'cert-err60-cpp' to 'bugprone-exception-copy-cons…
vbvictor Nov 10, 2025
abdb9a0
[gn build] Port 4b433cbdeec7
llvmgnsyncbot Nov 10, 2025
d0081aa
[NFC][SPIRV] Make the zero-length-array.ll test explicit about what i…
jmmartinez Nov 10, 2025
eaa889a
[clang-tidy] Add fine-graded configuration for 'bugprone-exception-es…
vbvictor Nov 10, 2025
3637f66
[RISCV][TTI] Fix crash of non-built-in vector type cost quering. (#16…
ElvisWang123 Nov 10, 2025
152bda7
[libc++] Replace the last uses of __tuple_types with __type_list (#16…
philnik777 Nov 10, 2025
6ef174c
[gn build] Port 152bda726958
llvmgnsyncbot Nov 10, 2025
471dbb9
[libc++] Replace __libcpp_is_final with a variable template (#167137)
philnik777 Nov 10, 2025
0b52b82
[libc++] Merge insert/emplace(const_iterator, Args...) implementation…
philnik777 Nov 10, 2025
57dad86
[SPIRV] Fix failing assertion in SPIRVAsmPrinter (#166909)
jmmartinez Nov 10, 2025
d84a911
[AArch64][SVE] Avoid redundant extend of unsigned i8/i16 extracts. (#…
rj-jesus Nov 10, 2025
ff1efe9
[AArch64] Combine subtract with borrow to SBC. (#165271)
rj-jesus Nov 10, 2025
898d6fe
Remove unused <algorithm> inclusion (#166942)
serge-sans-paille Nov 10, 2025
2d1d5fe
[VPlan] Simplify branch-cond with getVectorTripCount (#155604)
artagnon Nov 10, 2025
80fa6e1
[DropAssumes] Drop dereferenceable assumptions after vectorization. (…
fhahn Nov 10, 2025
0e6c8da
[X86] ldexp-avx512.ll - add v8f16/v16f16/v32f16 test coverage for #16…
RKSimon Nov 10, 2025
54d86df
[AArch64] Fallback to PRFUM for PRFM with negative or unaligned offse…
c-rhodes Nov 10, 2025
b18d828
[tools][llc] Make save-stats.ll test target independent (#167238)
tomershafir Nov 10, 2025
1ffe79d
[libc++] Avoid overloaded `operator,` for (`T`, `Iter`) cases (#161049)
frederick-vs-ja Nov 10, 2025
3170777
merge main into amd-staging
z1-cciauto Nov 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "DynamicStaticInitializersCheck.h"
#include "EasilySwappableParametersCheck.h"
#include "EmptyCatchCheck.h"
#include "ExceptionCopyConstructorThrowsCheck.h"
#include "ExceptionEscapeCheck.h"
#include "FloatLoopCounterCheck.h"
#include "FoldInitTypeCheck.h"
Expand Down Expand Up @@ -155,6 +156,8 @@ class BugproneModule : public ClangTidyModule {
CheckFactories.registerCheck<EasilySwappableParametersCheck>(
"bugprone-easily-swappable-parameters");
CheckFactories.registerCheck<EmptyCatchCheck>("bugprone-empty-catch");
CheckFactories.registerCheck<ExceptionCopyConstructorThrowsCheck>(
"bugprone-exception-copy-constructor-throws");
CheckFactories.registerCheck<ExceptionEscapeCheck>(
"bugprone-exception-escape");
CheckFactories.registerCheck<FloatLoopCounterCheck>(
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ add_clang_library(clangTidyBugproneModule STATIC
DynamicStaticInitializersCheck.cpp
EasilySwappableParametersCheck.cpp
EmptyCatchCheck.cpp
ExceptionCopyConstructorThrowsCheck.cpp
ExceptionEscapeCheck.cpp
FloatLoopCounterCheck.cpp
FoldInitTypeCheck.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
//
//===----------------------------------------------------------------------===//

#include "ThrownExceptionTypeCheck.h"
#include "ExceptionCopyConstructorThrowsCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"

using namespace clang::ast_matchers;

namespace clang::tidy::cert {
namespace clang::tidy::bugprone {

void ThrownExceptionTypeCheck::registerMatchers(MatchFinder *Finder) {
void ExceptionCopyConstructorThrowsCheck::registerMatchers(
MatchFinder *Finder) {
Finder->addMatcher(
traverse(
TK_AsIs,
Expand All @@ -25,10 +26,11 @@ void ThrownExceptionTypeCheck::registerMatchers(MatchFinder *Finder) {
this);
}

void ThrownExceptionTypeCheck::check(const MatchFinder::MatchResult &Result) {
void ExceptionCopyConstructorThrowsCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *E = Result.Nodes.getNodeAs<Expr>("expr");
diag(E->getExprLoc(),
"thrown exception type is not nothrow copy constructible");
}

} // namespace clang::tidy::cert
} // namespace clang::tidy::bugprone
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_THROWNEXCEPTIONTYPECHECK_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_THROWNEXCEPTIONTYPECHECK_H
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONCOPYCONSTRUCTORTHROWSCHECK_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONCOPYCONSTRUCTORTHROWSCHECK_H

#include "../ClangTidyCheck.h"

namespace clang::tidy::cert {
namespace clang::tidy::bugprone {

/// Checks whether a thrown object is nothrow copy constructible.
///
/// For the user-facing documentation see:
/// https://clang.llvm.org/extra/clang-tidy/checks/cert/err60-cpp.html
class ThrownExceptionTypeCheck : public ClangTidyCheck {
/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/exception-copy-constructor-throws.html
class ExceptionCopyConstructorThrowsCheck : public ClangTidyCheck {
public:
ThrownExceptionTypeCheck(StringRef Name, ClangTidyContext *Context)
ExceptionCopyConstructorThrowsCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
Expand All @@ -28,6 +28,6 @@ class ThrownExceptionTypeCheck : public ClangTidyCheck {
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

} // namespace clang::tidy::cert
} // namespace clang::tidy::bugprone

#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_THROWNEXCEPTIONTYPECHECK_H
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONCOPYCONSTRUCTORTHROWSCHECK_H
42 changes: 32 additions & 10 deletions clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,22 @@ ExceptionEscapeCheck::ExceptionEscapeCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context), RawFunctionsThatShouldNotThrow(Options.get(
"FunctionsThatShouldNotThrow", "")),
RawIgnoredExceptions(Options.get("IgnoredExceptions", "")) {
RawIgnoredExceptions(Options.get("IgnoredExceptions", "")),
RawCheckedSwapFunctions(
Options.get("CheckedSwapFunctions", "swap,iter_swap,iter_move")),
CheckDestructors(Options.get("CheckDestructors", true)),
CheckMoveMemberFunctions(Options.get("CheckMoveMemberFunctions", true)),
CheckMain(Options.get("CheckMain", true)),
CheckNothrowFunctions(Options.get("CheckNothrowFunctions", true)) {
llvm::SmallVector<StringRef, 8> FunctionsThatShouldNotThrowVec,
IgnoredExceptionsVec;
IgnoredExceptionsVec, CheckedSwapFunctionsVec;
RawFunctionsThatShouldNotThrow.split(FunctionsThatShouldNotThrowVec, ",", -1,
false);
FunctionsThatShouldNotThrow.insert_range(FunctionsThatShouldNotThrowVec);

RawCheckedSwapFunctions.split(CheckedSwapFunctionsVec, ",", -1, false);
CheckedSwapFunctions.insert_range(CheckedSwapFunctionsVec);

llvm::StringSet<> IgnoredExceptions;
RawIgnoredExceptions.split(IgnoredExceptionsVec, ",", -1, false);
IgnoredExceptions.insert_range(IgnoredExceptionsVec);
Expand All @@ -54,20 +63,33 @@ void ExceptionEscapeCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "FunctionsThatShouldNotThrow",
RawFunctionsThatShouldNotThrow);
Options.store(Opts, "IgnoredExceptions", RawIgnoredExceptions);
Options.store(Opts, "CheckedSwapFunctions", RawCheckedSwapFunctions);
Options.store(Opts, "CheckDestructors", CheckDestructors);
Options.store(Opts, "CheckMoveMemberFunctions", CheckMoveMemberFunctions);
Options.store(Opts, "CheckMain", CheckMain);
Options.store(Opts, "CheckNothrowFunctions", CheckNothrowFunctions);
}

void ExceptionEscapeCheck::registerMatchers(MatchFinder *Finder) {
auto MatchIf = [](bool Enabled, const auto &Matcher) {
ast_matchers::internal::Matcher<FunctionDecl> Nothing = unless(anything());
return Enabled ? Matcher : Nothing;
};
Finder->addMatcher(
functionDecl(
isDefinition(),
anyOf(isNoThrow(),
allOf(anyOf(cxxDestructorDecl(),
cxxConstructorDecl(isMoveConstructor()),
cxxMethodDecl(isMoveAssignmentOperator()), isMain(),
allOf(hasAnyName("swap", "iter_swap", "iter_move"),
hasAtLeastOneParameter())),
unless(isExplicitThrow())),
isEnabled(FunctionsThatShouldNotThrow)))
anyOf(
MatchIf(CheckNothrowFunctions, isNoThrow()),
allOf(anyOf(MatchIf(CheckDestructors, cxxDestructorDecl()),
MatchIf(
CheckMoveMemberFunctions,
anyOf(cxxConstructorDecl(isMoveConstructor()),
cxxMethodDecl(isMoveAssignmentOperator()))),
MatchIf(CheckMain, isMain()),
allOf(isEnabled(CheckedSwapFunctions),
hasAtLeastOneParameter())),
unless(isExplicitThrow())),
isEnabled(FunctionsThatShouldNotThrow)))
.bind("thrower"),
this);
}
Expand Down
7 changes: 7 additions & 0 deletions clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@ class ExceptionEscapeCheck : public ClangTidyCheck {
private:
StringRef RawFunctionsThatShouldNotThrow;
StringRef RawIgnoredExceptions;
StringRef RawCheckedSwapFunctions;

const bool CheckDestructors;
const bool CheckMoveMemberFunctions;
const bool CheckMain;
const bool CheckNothrowFunctions;

llvm::StringSet<> FunctionsThatShouldNotThrow;
llvm::StringSet<> CheckedSwapFunctions;
utils::ExceptionAnalyzer Tracer;
};

Expand Down
5 changes: 3 additions & 2 deletions clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "../bugprone/CommandProcessorCheck.h"
#include "../bugprone/CopyConstructorMutatesArgumentCheck.h"
#include "../bugprone/DefaultOperatorNewOnOveralignedTypeCheck.h"
#include "../bugprone/ExceptionCopyConstructorThrowsCheck.h"
#include "../bugprone/FloatLoopCounterCheck.h"
#include "../bugprone/PointerArithmeticOnPolymorphicObjectCheck.h"
#include "../bugprone/RawMemoryCallOnNonTrivialTypeCheck.h"
Expand Down Expand Up @@ -41,7 +42,6 @@
#include "../readability/UppercaseLiteralSuffixCheck.h"
#include "LimitedRandomnessCheck.h"
#include "ProperlySeededRandomGeneratorCheck.h"
#include "ThrownExceptionTypeCheck.h"

namespace {

Expand Down Expand Up @@ -262,7 +262,8 @@ class CERTModule : public ClangTidyModule {
"cert-err52-cpp");
CheckFactories.registerCheck<bugprone::ThrowingStaticInitializationCheck>(
"cert-err58-cpp");
CheckFactories.registerCheck<ThrownExceptionTypeCheck>("cert-err60-cpp");
CheckFactories.registerCheck<bugprone::ExceptionCopyConstructorThrowsCheck>(
"cert-err60-cpp");
CheckFactories.registerCheck<misc::ThrowByValueCatchByReferenceCheck>(
"cert-err61-cpp");
// MEM
Expand Down
1 change: 0 additions & 1 deletion clang-tools-extra/clang-tidy/cert/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ add_clang_library(clangTidyCERTModule STATIC
CERTTidyModule.cpp
LimitedRandomnessCheck.cpp
ProperlySeededRandomGeneratorCheck.cpp
ThrownExceptionTypeCheck.cpp

LINK_LIBS
clangTidy
Expand Down
8 changes: 7 additions & 1 deletion clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ New check aliases
<clang-tidy/checks/bugprone/throwing-static-initialization>`
keeping initial check as an alias to the new one.

- Renamed :doc:`cert-err60-cpp <clang-tidy/checks/cert/err60-cpp>` to
:doc:`bugprone-exception-copy-constructor-throws
<clang-tidy/checks/bugprone/exception-copy-constructor-throws>`

- Renamed :doc:`cert-flp30-c <clang-tidy/checks/cert/flp30-c>` to
:doc:`bugprone-float-loop-counter
<clang-tidy/checks/bugprone/float-loop-counter>`
Expand Down Expand Up @@ -302,7 +306,9 @@ Changes in existing checks
exceptions from captures are now diagnosed, exceptions in the bodies of
lambdas that aren't actually invoked are not. Additionally, fixed an issue
where the check wouldn't diagnose throws in arguments to functions or
constructors.
constructors. Added fine-grained configuration via options
`CheckDestructors`, `CheckMoveMemberFunctions`, `CheckMain`,
`CheckedSwapFunctions`, and `CheckNothrowFunctions`.

- Improved :doc:`bugprone-infinite-loop
<clang-tidy/checks/bugprone/infinite-loop>` check by adding detection for
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.. title:: clang-tidy - bugprone-exception-copy-constructor-throws

bugprone-exception-copy-constructor-throws
==========================================

Checks whether a thrown object's copy constructor can throw.

Exception objects are required to be copy constructible in C++. However, an
exception's copy constructor should not throw to avoid potential issues when
unwinding the stack. If an exception is thrown during stack unwinding (such
as from a copy constructor of an exception object), the program will
terminate via ``std::terminate``.

.. code-block:: c++

class SomeException {
public:
SomeException() = default;
SomeException(const SomeException&) { /* may throw */ }
};

void f() {
throw SomeException(); // warning: thrown exception type's copy constructor can throw
}

References
----------

This check corresponds to the CERT C++ Coding Standard rule
`ERR60-CPP. Exception objects must be nothrow copy constructible
<https://wiki.sei.cmu.edu/confluence/display/cplusplus/ERR60-CPP.+Exception+objects+must+be+nothrow+copy+constructible>`_.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,31 @@ WARNING! This check may be expensive on large source files.
Options
-------

.. option:: CheckDestructors

When `true`, destructors are analyzed to not throw exceptions.
Default value is `true`.

.. option:: CheckMoveMemberFunctions

When `true`, move constructors and move assignment operators are analyzed
to not throw exceptions. Default value is `true`.

.. option:: CheckMain

When `true`, the ``main()`` function is analyzed to not throw exceptions.
Default value is `true`.

.. option:: CheckNothrowFunctions

When `true`, functions marked with ``noexcept`` or ``throw()`` exception
specifications are analyzed to not throw exceptions. Default value is `true`.

.. option:: CheckedSwapFunctions

Comma-separated list of swap function names which should not throw exceptions.
Default value is `swap,iter_swap,iter_move`.

.. option:: FunctionsThatShouldNotThrow

Comma separated list containing function names which should not throw. An
Expand Down
9 changes: 6 additions & 3 deletions clang-tools-extra/docs/clang-tidy/checks/cert/err60-cpp.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
.. title:: clang-tidy - cert-err60-cpp
.. meta::
:http-equiv=refresh: 5;URL=../bugprone/exception-copy-constructor-throws.html

cert-err60-cpp
==============

This check flags all throw expressions where the exception object is not nothrow
copy constructible.
The `cert-err60-cpp` check is an alias, please see
`bugprone-exception-copy-constructor-throws <../bugprone/exception-copy-constructor-throws.html>`_
for more information.

This check corresponds to the CERT C++ Coding Standard rule
`ERR60-CPP. Exception objects must be nothrow copy constructible
<https://www.securecoding.cert.org/confluence/display/cplusplus/ERR60-CPP.+Exception+objects+must+be+nothrow+copy+constructible>`_.
<https://wiki.sei.cmu.edu/confluence/display/cplusplus/ERR60-CPP.+Exception+objects+must+be+nothrow+copy+constructible>`_.
3 changes: 3 additions & 0 deletions clang-tools-extra/docs/clang-tidy/checks/list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Clang-Tidy Checks
:doc:`bugprone-dynamic-static-initializers <bugprone/dynamic-static-initializers>`,
:doc:`bugprone-easily-swappable-parameters <bugprone/easily-swappable-parameters>`,
:doc:`bugprone-empty-catch <bugprone/empty-catch>`,
:doc:`bugprone-exception-copy-constructor-throws <bugprone/exception-copy-constructor-throws>`,
:doc:`bugprone-exception-escape <bugprone/exception-escape>`,
:doc:`bugprone-float-loop-counter <bugprone/float-loop-counter>`,
:doc:`bugprone-fold-init-type <bugprone/fold-init-type>`,
Expand Down Expand Up @@ -180,6 +181,7 @@ Clang-Tidy Checks
:doc:`bugprone-virtual-near-miss <bugprone/virtual-near-miss>`, "Yes"
:doc:`cert-err33-c <cert/err33-c>`,
:doc:`cert-err60-cpp <cert/err60-cpp>`,
:doc:`cert-flp30-c <cert/flp30-c>`,
:doc:`cert-msc50-cpp <cert/msc50-cpp>`,
:doc:`cert-msc51-cpp <cert/msc51-cpp>`,
:doc:`cert-oop58-cpp <cert/oop58-cpp>`,
Expand Down Expand Up @@ -449,6 +451,7 @@ Check aliases
:doc:`cert-err34-c <cert/err34-c>`, :doc:`bugprone-unchecked-string-to-number-conversion <bugprone/unchecked-string-to-number-conversion>`,
:doc:`cert-err52-cpp <cert/err52-cpp>`, :doc:`modernize-avoid-setjmp-longjmp <modernize/avoid-setjmp-longjmp>`,
:doc:`cert-err58-cpp <cert/err58-cpp>`, :doc:`bugprone-throwing-static-initialization <bugprone/throwing-static-initialization>`,
:doc:`cert-err60-cpp <cert/err60-cpp>`, :doc:`bugprone-exception-copy-constructor-throws <bugprone/exception-copy-constructor-throws>`,
:doc:`cert-err61-cpp <cert/err61-cpp>`, :doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`,
:doc:`cert-exp42-c <cert/exp42-c>`, :doc:`bugprone-suspicious-memory-comparison <bugprone/suspicious-memory-comparison>`,
:doc:`cert-fio38-c <cert/fio38-c>`, :doc:`misc-non-copyable-objects <misc/non-copyable-objects>`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %check_clang_tidy -std=c++11,c++14 %s cert-err60-cpp %t -- -- -fcxx-exceptions
// RUN: %check_clang_tidy -std=c++11,c++14 %s bugprone-exception-copy-constructor-throws %t -- -- -fcxx-exceptions
// FIXME: Split off parts of this test that rely on dynamic exception
// specifications, and run this test in all language modes.
// FIXME: Fix the checker to work in C++17 or later mode.
Expand Down Expand Up @@ -92,7 +92,7 @@ void f() {
throw U(); // ok
throw V(); // ok
throw W(); // match, noexcept(false)
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: thrown exception type is not nothrow copy constructible [cert-err60-cpp]
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: thrown exception type is not nothrow copy constructible [bugprone-exception-copy-constructor-throws]
throw X(); // match, no noexcept clause, nontrivial
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: thrown exception type is not nothrow copy constructible
throw Y(); // ok
Expand Down
Loading