Skip to content

Commit

Permalink
Merged master:7d507ff55f6 into amd-gfx:8f20270d5ce
Browse files Browse the repository at this point in the history
Local branch amd-gfx 8f20270 Merge remote-tracking branch 'llvm/master' into HEAD
Remote branch master 7d507ff [PowerPC] Fix missing GOT indirect variant kind
  • Loading branch information
Sw authored and Sw committed May 6, 2020
2 parents 8f20270 + 7d507ff commit 7b0a59c
Show file tree
Hide file tree
Showing 194 changed files with 7,122 additions and 2,318 deletions.
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/add_new_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def adapt_module(module_path, module, check_name, check_name_camel):
lines = iter(lines)
try:
while True:
line = lines.next()
line = next(lines)
if not header_added:
match = re.search('#include "(.*)"', line)
if match:
Expand All @@ -197,7 +197,7 @@ def adapt_module(module_path, module, check_name, check_name_camel):
# If we didn't find the check name on this line, look on the
# next one.
prev_line = line
line = lines.next()
line = next(lines)
match = re.search(' *"([^"]*)"', line)
if match:
current_check_name = match.group(1)
Expand Down
28 changes: 17 additions & 11 deletions clang-tools-extra/clang-tidy/bugprone/SignedCharMisuseCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ static Matcher<TypedefDecl> hasAnyListedName(const std::string &Names) {
SignedCharMisuseCheck::SignedCharMisuseCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
CharTypdefsToIgnoreList(Options.get("CharTypdefsToIgnore", "")) {}
CharTypdefsToIgnoreList(Options.get("CharTypdefsToIgnore", "")),
DiagnoseSignedUnsignedCharComparisons(
Options.get("DiagnoseSignedUnsignedCharComparisons", true)) {}

void SignedCharMisuseCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "CharTypdefsToIgnore", CharTypdefsToIgnoreList);
Options.store(Opts, "DiagnoseSignedUnsignedCharComparisons",
DiagnoseSignedUnsignedCharComparisons);
}

// Create a matcher for char -> integer cast.
Expand Down Expand Up @@ -92,16 +96,18 @@ void SignedCharMisuseCheck::registerMatchers(MatchFinder *Finder) {

Finder->addMatcher(Declaration, this);

// Catch signed char/unsigned char comparison.
const auto CompareOperator =
expr(binaryOperator(hasAnyOperatorName("==", "!="),
anyOf(allOf(hasLHS(SignedCharCastExpr),
hasRHS(UnSignedCharCastExpr)),
allOf(hasLHS(UnSignedCharCastExpr),
hasRHS(SignedCharCastExpr)))))
.bind("comparison");

Finder->addMatcher(CompareOperator, this);
if (DiagnoseSignedUnsignedCharComparisons) {
// Catch signed char/unsigned char comparison.
const auto CompareOperator =
expr(binaryOperator(hasAnyOperatorName("==", "!="),
anyOf(allOf(hasLHS(SignedCharCastExpr),
hasRHS(UnSignedCharCastExpr)),
allOf(hasLHS(UnSignedCharCastExpr),
hasRHS(SignedCharCastExpr)))))
.bind("comparison");

Finder->addMatcher(CompareOperator, this);
}

// Catch array subscripts with signed char -> integer conversion.
// Matcher for C arrays.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SignedCharMisuseCheck : public ClangTidyCheck {
const std::string &CastBindName) const;

const std::string CharTypdefsToIgnoreList;
const bool DiagnoseSignedUnsignedCharComparisons;
};

} // namespace bugprone
Expand Down
5 changes: 5 additions & 0 deletions clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "../ClangTidyModuleRegistry.h"
#include "../bugprone/BadSignalToKillThreadCheck.h"
#include "../bugprone/ReservedIdentifierCheck.h"
#include "../bugprone/SignedCharMisuseCheck.h"
#include "../bugprone/SpuriouslyWakeUpFunctionsCheck.h"
#include "../bugprone/UnhandledSelfAssignmentCheck.h"
#include "../google/UnnamedNamespaceInHeaderCheck.h"
Expand Down Expand Up @@ -108,13 +109,17 @@ class CERTModule : public ClangTidyModule {
// POS
CheckFactories.registerCheck<bugprone::BadSignalToKillThreadCheck>(
"cert-pos44-c");
// STR
CheckFactories.registerCheck<bugprone::SignedCharMisuseCheck>(
"cert-str34-c");
}

ClangTidyOptions getModuleOptions() override {
ClangTidyOptions Options;
ClangTidyOptions::OptionMap &Opts = Options.CheckOptions;
Opts["cert-dcl16-c.NewSuffixes"] = "L;LL;LU;LLU";
Opts["cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField"] = "0";
Opts["cert-str34-c.DiagnoseSignedUnsignedCharComparisons"] = "0";
return Options;
}
};
Expand Down
18 changes: 12 additions & 6 deletions clang-tools-extra/clang-tidy/performance/ForRangeCopyCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ void ForRangeCopyCheck::registerMatchers(MatchFinder *Finder) {
// Match loop variables that are not references or pointers or are already
// initialized through MaterializeTemporaryExpr which indicates a type
// conversion.
auto LoopVar = varDecl(
hasType(qualType(
unless(anyOf(hasCanonicalType(anyOf(referenceType(), pointerType())),
hasDeclaration(namedDecl(
matchers::matchesAnyListedName(AllowedTypes))))))),
unless(hasInitializer(expr(hasDescendant(materializeTemporaryExpr())))));
auto HasReferenceOrPointerTypeOrIsAllowed = hasType(qualType(
unless(anyOf(hasCanonicalType(anyOf(referenceType(), pointerType())),
hasDeclaration(namedDecl(
matchers::matchesAnyListedName(AllowedTypes)))))));
auto IteratorReturnsValueType = cxxOperatorCallExpr(
hasOverloadedOperatorName("*"),
callee(
cxxMethodDecl(returns(unless(hasCanonicalType(referenceType()))))));
auto LoopVar =
varDecl(HasReferenceOrPointerTypeOrIsAllowed,
unless(hasInitializer(expr(hasDescendant(expr(anyOf(
materializeTemporaryExpr(), IteratorReturnsValueType)))))));
Finder->addMatcher(cxxForRangeStmt(hasLoopVariable(LoopVar.bind("loopVar")))
.bind("forRange"),
this);
Expand Down
5 changes: 5 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ New check aliases
:doc:`bugprone-reserved-identifier
<clang-tidy/checks/bugprone-reserved-identifier>` was added.

- New alias :doc:`cert-str34-c
<clang-tidy/checks/cert-str34-c>` to
:doc:`bugprone-signed-char-misuse
<clang-tidy/checks/bugprone-signed-char-misuse>` was added.

Changes in existing checks
^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
bugprone-signed-char-misuse
===========================

`cert-str34-c` redirects here as an alias for this check. For the CERT alias,
the `DiagnoseSignedUnsignedCharComparisons` option is set to `0`.

Finds those ``signed char`` -> integer conversions which might indicate a
programming error. The basic problem with the ``signed char``, that it might
store the non-ASCII characters as negative values. This behavior can cause a
Expand Down Expand Up @@ -108,3 +111,8 @@ so both arguments will have the same type.
check. This is useful when a typedef introduces an integer alias like
``sal_Int8`` or ``int8_t``. In this case, human misinterpretation is not
an issue.

.. option:: DiagnoseSignedUnsignedCharComparisons

When nonzero, the check will warn on ``signed char``/``unsigned char`` comparisons,
otherwise these comparisons are ignored. By default, this option is set to ``1``.
10 changes: 10 additions & 0 deletions clang-tools-extra/docs/clang-tidy/checks/cert-str34-c.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. title:: clang-tidy - cert-str34-c
.. meta::
:http-equiv=refresh: 5;URL=bugprone-signed-char-misuse.html

cert-str34-c
============

The cert-str34-c check is an alias, please see
`bugprone-signed-char-misuse <bugprone-signed-char-misuse.html>`_
for more information.
1 change: 1 addition & 0 deletions clang-tools-extra/docs/clang-tidy/checks/list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ Clang-Tidy Checks
`cert-oop11-cpp <cert-oop11-cpp.html>`_, `performance-move-constructor-init <performance-move-constructor-init.html>`_, "Yes"
`cert-oop54-cpp <cert-oop54-cpp.html>`_, `bugprone-unhandled-self-assignment <bugprone-unhandled-self-assignment.html>`_,
`cert-pos44-c <cert-pos44-c.html>`_, `bugprone-bad-signal-to-kill-thread <bugprone-bad-signal-to-kill-thread.html>`_,
`cert-str34-c <cert-str34-c.html>`_, `bugprone-signed-char-misuse <bugprone-signed-char-misuse.html>`_,
`clang-analyzer-core.CallAndMessage <clang-analyzer-core.CallAndMessage.html>`_, `Clang Static Analyzer <https://clang.llvm.org/docs/analyzer/checkers.html>`_,
`clang-analyzer-core.DivideZero <clang-analyzer-core.DivideZero.html>`_, `Clang Static Analyzer <https://clang.llvm.org/docs/analyzer/checkers.html>`_,
`clang-analyzer-core.NonNullParamChecker <clang-analyzer-core.NonNullParamChecker.html>`_, `Clang Static Analyzer <https://clang.llvm.org/docs/analyzer/checkers.html>`_,
Expand Down
18 changes: 18 additions & 0 deletions clang-tools-extra/test/clang-tidy/checkers/cert-str34-c.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: %check_clang_tidy %s cert-str34-c %t

// Check whether alias is actually working.
int SimpleVarDeclaration() {
signed char CCharacter = -5;
int NCharacter = CCharacter;
// CHECK-MESSAGES: [[@LINE-1]]:20: warning: 'signed char' to 'int' conversion; consider casting to 'unsigned char' first. [cert-str34-c]

return NCharacter;
}

// Check whether bugprone-signed-char-misuse.DiagnoseSignedUnsignedCharComparisons option is set correctly.
int SignedUnsignedCharEquality(signed char SCharacter) {
unsigned char USCharacter = 'a';
if (SCharacter == USCharacter) // no warning
return 1;
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct Iterator {
};
template <typename T>
struct View {
View() = default;
T begin() { return T(); }
T begin() const { return T(); }
T end() { return T(); }
Expand Down Expand Up @@ -270,3 +271,28 @@ void IgnoreLoopVariableNotUsedInLoopBody() {
for (auto _ : View<Iterator<S>>()) {
}
}

template <typename T>
struct ValueReturningIterator {
void operator++() {}
T operator*() { return T(); }
bool operator!=(const ValueReturningIterator &) { return false; }
typedef const T &const_reference;
};

void negativeValueIterator() {
// Check does not trigger for iterators that return elements by value.
for (const S SS : View<ValueReturningIterator<S>>()) {
}
}

View<Iterator<S>> createView(S) { return View<Iterator<S>>(); }

void positiveValueIteratorUsedElseWhere() {
for (const S SS : createView(*ValueReturningIterator<S>())) {
// CHECK-MESSAGES: [[@LINE-1]]:16: warning: the loop variable's type is not
// a reference type; this creates a copy in each iteration; consider making
// this a reference [performance-for-range-copy] CHECK-FIXES: for (const S&
// SS : createView(*ValueReturningIterator<S>())) {
}
}
3 changes: 0 additions & 3 deletions clang/cmake/caches/CrossWinToARMLinux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ set(LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXX OFF CACHE BOOL "")
set(LIBCXX_LINK_TESTS_WITH_SHARED_LIBCXXABI OFF CACHE BOOL "")
set(LIBCXX_LINK_TESTS_WITH_SHARED_LIBCXX OFF CACHE BOOL "")

# FIXME: Remove this when https://reviews.llvm.org/D78200 is merged.
set(LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")

set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
set(LIBCXX_TARGET_TRIPLE "${CMAKE_C_COMPILER_TARGET}" CACHE STRING "")
set(LIBCXX_SYSROOT "${DEFAULT_SYSROOT}" CACHE STRING "")
Expand Down
Loading

0 comments on commit 7b0a59c

Please sign in to comment.