Skip to content

Commit

Permalink
Merged master:49fb4a96e0b into amd-gfx:1613c2ba305
Browse files Browse the repository at this point in the history
Local branch amd-gfx 1613c2b Merged master:fdf3d1766bb into amd-gfx:82c58d0dd35
Remote branch master 49fb4a9 change LLVM_VERSION_SUFFIX default from svn to git
  • Loading branch information
Sw authored and Sw committed Nov 11, 2019
2 parents 1613c2b + 49fb4a9 commit c8e1ec4
Show file tree
Hide file tree
Showing 36 changed files with 235 additions and 136 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//===--- BadSignalToKillThreadCheck.cpp - clang-tidy ---------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "BadSignalToKillThreadCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"

using namespace clang::ast_matchers;

namespace clang {
namespace tidy {
namespace bugprone {

void BadSignalToKillThreadCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
callExpr(allOf(callee(functionDecl(hasName("::pthread_kill"))),
argumentCountIs(2)),
hasArgument(1, integerLiteral().bind("integer-literal")))
.bind("thread-kill"),
this);
}

static Preprocessor *PP;

void BadSignalToKillThreadCheck::check(const MatchFinder::MatchResult &Result) {
const auto IsSigterm = [](const auto &KeyValue) -> bool {
return KeyValue.first->getName() == "SIGTERM";
};
const auto TryExpandAsInteger =
[](Preprocessor::macro_iterator It) -> Optional<unsigned> {
if (It == PP->macro_end())
return llvm::None;
const MacroInfo *MI = PP->getMacroInfo(It->first);
const Token &T = MI->tokens().back();
StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());

llvm::APInt IntValue;
constexpr unsigned AutoSenseRadix = 0;
if (ValueStr.getAsInteger(AutoSenseRadix, IntValue))
return llvm::None;
return IntValue.getZExtValue();
};

const auto SigtermMacro = llvm::find_if(PP->macros(), IsSigterm);

if (!SigtermValue && !(SigtermValue = TryExpandAsInteger(SigtermMacro)))
return;

const auto *MatchedExpr = Result.Nodes.getNodeAs<Expr>("thread-kill");
const auto *MatchedIntLiteral =
Result.Nodes.getNodeAs<IntegerLiteral>("integer-literal");
if (MatchedIntLiteral->getValue() == *SigtermValue) {
diag(MatchedExpr->getBeginLoc(),
"thread should not be terminated by raising the 'SIGTERM' signal");
}
}

void BadSignalToKillThreadCheck::registerPPCallbacks(
const SourceManager &SM, Preprocessor *pp, Preprocessor *ModuleExpanderPP) {
PP = pp;
}

} // namespace bugprone
} // namespace tidy
} // namespace clang
37 changes: 37 additions & 0 deletions clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//===--- BadSignalToKillThreadCheck.h - clang-tidy --------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_BADSIGNALTOKILLTHREADCHECK_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_BADSIGNALTOKILLTHREADCHECK_H

#include "../ClangTidyCheck.h"

namespace clang {
namespace tidy {
namespace bugprone {

/// Finds ``pthread_kill`` function calls when thread is terminated by
/// ``SIGTERM`` signal.
/// For the user-facing documentation see:
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-bad-signal-to-kill-thread.html
class BadSignalToKillThreadCheck : public ClangTidyCheck {
public:
BadSignalToKillThreadCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override;
Optional<unsigned> SigtermValue;
};

} // namespace bugprone
} // namespace tidy
} // namespace clang

#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_BADSIGNALTOKILLTHREADCHECK_H
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 @@ -12,6 +12,7 @@
#include "../cppcoreguidelines/NarrowingConversionsCheck.h"
#include "ArgumentCommentCheck.h"
#include "AssertSideEffectCheck.h"
#include "BadSignalToKillThreadCheck.h"
#include "BoolPointerImplicitConversionCheck.h"
#include "BranchCloneCheck.h"
#include "CopyConstructorInitCheck.h"
Expand Down Expand Up @@ -68,6 +69,8 @@ class BugproneModule : public ClangTidyModule {
"bugprone-argument-comment");
CheckFactories.registerCheck<AssertSideEffectCheck>(
"bugprone-assert-side-effect");
CheckFactories.registerCheck<BadSignalToKillThreadCheck>(
"bugprone-bad-signal-to-kill-thread");
CheckFactories.registerCheck<BoolPointerImplicitConversionCheck>(
"bugprone-bool-pointer-implicit-conversion");
CheckFactories.registerCheck<BranchCloneCheck>(
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 @@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS support)
add_clang_library(clangTidyBugproneModule
ArgumentCommentCheck.cpp
AssertSideEffectCheck.cpp
BadSignalToKillThreadCheck.cpp
BoolPointerImplicitConversionCheck.cpp
BranchCloneCheck.cpp
BugproneTidyModule.cpp
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "../ClangTidyModule.h"
#include "../ClangTidyModuleRegistry.h"
#include "../bugprone/UnhandledSelfAssignmentCheck.h"
#include "../bugprone/BadSignalToKillThreadCheck.h"
#include "../google/UnnamedNamespaceInHeaderCheck.h"
#include "../misc/NewDeleteOverloadsCheck.h"
#include "../misc/NonCopyableObjects.h"
Expand Down Expand Up @@ -82,6 +83,9 @@ class CERTModule : public ClangTidyModule {
CheckFactories.registerCheck<LimitedRandomnessCheck>("cert-msc30-c");
CheckFactories.registerCheck<ProperlySeededRandomGeneratorCheck>(
"cert-msc32-c");
// POS
CheckFactories.registerCheck<bugprone::BadSignalToKillThreadCheck>(
"cert-pos44-c");
}

ClangTidyOptions getModuleOptions() override {
Expand Down
11 changes: 11 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ The improvements are...
Improvements to clang-tidy
--------------------------

- New :doc:`bugprone-bad-signal-to-kill-thread
<clang-tidy/checks/bugprone-bad-signal-to-kill-thread>` check.

Finds ``pthread_kill`` function calls when a thread is terminated by
raising ``SIGTERM`` signal.

- New :doc:`bugprone-dynamic-static-initializers
<clang-tidy/checks/bugprone-dynamic-static-initializers>` check.

Expand All @@ -88,6 +94,11 @@ Improvements to clang-tidy
Without the null terminator it can result in undefined behaviour when the
string is read.

- New alias :doc:`cert-pos44-cpp
<clang-tidy/checks/cert-pos44-cpp>` to
:doc:`bugprone-bad-signal-to-kill-thread
<clang-tidy/checks/bugprone-bad-signal-to-kill-thread>` was added.

- New :doc:`cppcoreguidelines-init-variables
<clang-tidy/checks/cppcoreguidelines-init-variables>` check.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.. title:: clang-tidy - bugprone-bad-signal-to-kill-thread

bugprone-bad-signal-to-kill-thread
==================================

Finds ``pthread_kill`` function calls when a thread is terminated by
raising ``SIGTERM`` signal and the signal kills the entire process, not
just the individual thread. Use any signal except ``SIGTERM``.

.. code-block: c++
pthread_kill(thread, SIGTERM);
This check corresponds to the CERT C Coding Standard rule
`POS44-C. Do not use signals to terminate threads
<https://wiki.sei.cmu.edu/confluence/display/c/POS44-C.+Do+not+use+signals+to+terminate+threads>`_.
9 changes: 9 additions & 0 deletions clang-tools-extra/docs/clang-tidy/checks/cert-pos44-c.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.. title:: clang-tidy - cert-pos44-c
.. meta::
:http-equiv=refresh: 5;URL=bugprone-bad-signal-to-kill-thread.html

cert-pos44-c
============

The cert-pos44-c check is an alias, please see
`bugprone-bad-signal-to-kill-thread <bugprone-bad-signal-to-kill-thread.html>`_ for more information.
2 changes: 2 additions & 0 deletions clang-tools-extra/docs/clang-tidy/checks/list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Clang-Tidy Checks
boost-use-to-string
bugprone-argument-comment
bugprone-assert-side-effect
bugprone-bad-signal-to-kill-thread
bugprone-bool-pointer-implicit-conversion
bugprone-branch-clone
bugprone-copy-constructor-init
Expand Down Expand Up @@ -105,6 +106,7 @@ Clang-Tidy Checks
cert-msc51-cpp
cert-oop11-cpp (redirects to performance-move-constructor-init) <cert-oop11-cpp>
cert-oop54-cpp (redirects to bugprone-unhandled-self-assignment) <cert-oop54-cpp>
cert-pos44-c (redirects to bugprone-bad-signal-to-kill-thread) <cert-pos44-c>
clang-analyzer-core.CallAndMessage (redirects to https://clang.llvm.org/docs/analyzer/checkers) <clang-analyzer-core.CallAndMessage>
clang-analyzer-core.DivideZero (redirects to https://clang.llvm.org/docs/analyzer/checkers) <clang-analyzer-core.DivideZero>
clang-analyzer-core.DynamicTypePropagation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// RUN: %check_clang_tidy %s bugprone-bad-signal-to-kill-thread %t

#define SIGTERM 15
#define SIGINT 2
using pthread_t = int;
using pthread_attr_t = int;

int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine)(void *), void *arg);

int pthread_kill(pthread_t thread, int sig);

int pthread_cancel(pthread_t thread);

void *test_func_return_a_pointer(void *foo);

int main() {
int result;
pthread_t thread;

if ((result = pthread_create(&thread, nullptr, test_func_return_a_pointer, 0)) != 0) {
}
if ((result = pthread_kill(thread, SIGTERM)) != 0) {
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: thread should not be terminated by raising the 'SIGTERM' signal [bugprone-bad-signal-to-kill-thread]
}

//compliant solution
if ((result = pthread_cancel(thread)) != 0) {
}

if ((result = pthread_kill(thread, SIGINT)) != 0) {
}
if ((result = pthread_kill(thread, 0xF)) != 0) {
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: thread should not be terminated by raising the 'SIGTERM' signal [bugprone-bad-signal-to-kill-thread]
}

return 0;
}
4 changes: 3 additions & 1 deletion clang/tools/clang-format/clang-format-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

;;; Commentary:

;; Unit tests for clang-format.el.
;; Unit tests for clang-format.el. Not run by lit, run as:
;; emacs -Q -batch -l clang/tools/clang-format/clang-format.el -l clang/tools/clang-format/clang-format-test.el -f ert-run-tests-batch-and-exit

;;; Code:

Expand Down Expand Up @@ -58,6 +59,7 @@
(should-not display)
(should (equal args
'("-output-replacements-xml" "-assume-filename" "foo.cpp"
"-fallback-style" "none"
;; Beginning of buffer, no byte-order mark.
"-offset" "0"
;; We have two lines with 2×2 bytes for the umlauts,
Expand Down
2 changes: 1 addition & 1 deletion libcxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXX_STANDALONE_BUIL
project(libcxx CXX C)

set(PACKAGE_NAME libcxx)
set(PACKAGE_VERSION 10.0.0svn)
set(PACKAGE_VERSION 10.0.0git)
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")

Expand Down
2 changes: 1 addition & 1 deletion libunwind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBUNWIND_STANDALONE_B
endif()

set(PACKAGE_NAME libunwind)
set(PACKAGE_VERSION 10.0.0svn)
set(PACKAGE_VERSION 10.0.0git)
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")

Expand Down
4 changes: 0 additions & 4 deletions lldb/include/lldb/Interpreter/OptionValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ class OptionValue {
OptionValue()
: m_callback(nullptr), m_baton(nullptr), m_value_was_set(false) {}

OptionValue(const OptionValue &rhs)
: m_callback(rhs.m_callback), m_baton(rhs.m_baton),
m_value_was_set(rhs.m_value_was_set) {}

virtual ~OptionValue() = default;

// Subclasses should override these functions
Expand Down
10 changes: 0 additions & 10 deletions lldb/include/lldb/Symbol/Declaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,6 @@ class Declaration {
{
}

/// Construct with a reference to another Declaration object.
Declaration(const Declaration &rhs)
: m_file(rhs.m_file), m_line(rhs.m_line)
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
,
m_column(rhs.m_column)
#endif
{
}

/// Construct with a pointer to another Declaration object.
Declaration(const Declaration *decl_ptr)
: m_file(), m_line(0)
Expand Down
12 changes: 0 additions & 12 deletions lldb/include/lldb/Symbol/SymbolContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,6 @@ class SymbolContext {

~SymbolContext();

/// Assignment operator.
///
/// Copies the address value from another SymbolContext object \a rhs into
/// \a this object.
///
/// \param[in] rhs
/// A const SymbolContext object reference to copy.
///
/// \return
/// A const SymbolContext object reference to \a this.
const SymbolContext &operator=(const SymbolContext &rhs);

/// Clear the object's state.
///
/// Resets all pointer members to nullptr, and clears any class objects to
Expand Down
7 changes: 0 additions & 7 deletions lldb/include/lldb/Utility/ArchSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,6 @@ class ArchSpec {
/// Destructor.
~ArchSpec();

/// Assignment operator.
///
/// \param[in] rhs another ArchSpec object to copy.
///
/// \return A const reference to this object.
const ArchSpec &operator=(const ArchSpec &rhs);

/// Returns true if the OS, vendor and environment fields of the triple are
/// unset. The triple is expected to be normalized
/// (llvm::Triple::normalize).
Expand Down
1 change: 0 additions & 1 deletion lldb/include/lldb/Utility/Broadcaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class BroadcastEventSpec {
}

bool operator<(const BroadcastEventSpec &rhs) const;
BroadcastEventSpec &operator=(const BroadcastEventSpec &rhs);

private:
ConstString m_broadcaster_class;
Expand Down
11 changes: 0 additions & 11 deletions lldb/include/lldb/Utility/FileSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,6 @@ class FileSpec {

bool FileEquals(const FileSpec &other) const;

/// Assignment operator.
///
/// Makes a copy of the uniqued directory and filename strings from \a rhs.
///
/// \param[in] rhs
/// A const FileSpec object reference to assign to this object.
///
/// \return
/// A const reference to this object.
const FileSpec &operator=(const FileSpec &rhs);

/// Equal to operator
///
/// Tests if this object is equal to \a rhs.
Expand Down
11 changes: 0 additions & 11 deletions lldb/include/lldb/Utility/Flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ class Flags {
/// The initial value for all flags.
Flags(ValueType flags = 0) : m_flags(flags) {}

/// Copy constructor.
///
/// Construct and copy the flags from \a rhs.
///
/// \param[in] rhs
/// A const Flags object reference to copy.
Flags(const Flags &rhs) : m_flags(rhs.m_flags) {}

/// Destructor.
~Flags() {}

/// Get accessor for all flags.
///
/// \return
Expand Down
Loading

0 comments on commit c8e1ec4

Please sign in to comment.