Skip to content

Commit

Permalink
Merged master:0d7286a6523 into amd-gfx:7a72f3ba645
Browse files Browse the repository at this point in the history
Local branch amd-gfx 7a72f3b Merged master:e10e034f4bb into amd-gfx:af9b354efe9
Remote branch master 0d7286a [WebAssembly] Avoid scalarizing vector shifts in more cases
  • Loading branch information
Sw authored and Sw committed Jul 7, 2020
2 parents 7a72f3b + 0d7286a commit cba70fe
Show file tree
Hide file tree
Showing 60 changed files with 1,061 additions and 334 deletions.
2 changes: 2 additions & 0 deletions clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "MisplacedWideningCastCheck.h"
#include "MoveForwardingReferenceCheck.h"
#include "MultipleStatementMacroCheck.h"
#include "NoEscapeCheck.h"
#include "NotNullTerminatedResultCheck.h"
#include "ParentVirtualCallCheck.h"
#include "PosixReturnCheck.h"
Expand Down Expand Up @@ -120,6 +121,7 @@ class BugproneModule : public ClangTidyModule {
"bugprone-multiple-statement-macro");
CheckFactories.registerCheck<cppcoreguidelines::NarrowingConversionsCheck>(
"bugprone-narrowing-conversions");
CheckFactories.registerCheck<NoEscapeCheck>("bugprone-no-escape");
CheckFactories.registerCheck<NotNullTerminatedResultCheck>(
"bugprone-not-null-terminated-result");
CheckFactories.registerCheck<ParentVirtualCallCheck>(
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 @@ -29,6 +29,7 @@ add_clang_library(clangTidyBugproneModule
MisplacedWideningCastCheck.cpp
MoveForwardingReferenceCheck.cpp
MultipleStatementMacroCheck.cpp
NoEscapeCheck.cpp
NotNullTerminatedResultCheck.cpp
ParentVirtualCallCheck.cpp
PosixReturnCheck.cpp
Expand Down
51 changes: 51 additions & 0 deletions clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//===--- NoEscapeCheck.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 "NoEscapeCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"

using namespace clang::ast_matchers;

namespace clang {
namespace tidy {
namespace bugprone {

void NoEscapeCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(callExpr(callee(functionDecl(hasName("::dispatch_async"))),
argumentCountIs(2),
hasArgument(1, blockExpr().bind("arg-block"))),
this);
Finder->addMatcher(callExpr(callee(functionDecl(hasName("::dispatch_after"))),
argumentCountIs(3),
hasArgument(2, blockExpr().bind("arg-block"))),
this);
}

void NoEscapeCheck::check(const MatchFinder::MatchResult &Result) {
const auto *MatchedEscapingBlock =
Result.Nodes.getNodeAs<BlockExpr>("arg-block");
const BlockDecl *EscapingBlockDecl = MatchedEscapingBlock->getBlockDecl();
for (const BlockDecl::Capture &CapturedVar : EscapingBlockDecl->captures()) {
const VarDecl *Var = CapturedVar.getVariable();
if (Var && Var->hasAttr<NoEscapeAttr>()) {
// FIXME: Add a method to get the location of the use of a CapturedVar so
// that we can diagnose the use of the pointer instead of the block.
diag(MatchedEscapingBlock->getBeginLoc(),
"pointer %0 with attribute 'noescape' is captured by an "
"asynchronously-executed block")
<< Var;
diag(Var->getBeginLoc(), "the 'noescape' attribute is declared here.",
DiagnosticIDs::Note);
}
}
}

} // namespace bugprone
} // namespace tidy
} // namespace clang
39 changes: 39 additions & 0 deletions clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//===--- NoEscapeCheck.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_NOESCAPECHECK_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NOESCAPECHECK_H

#include "../ClangTidyCheck.h"

namespace clang {
namespace tidy {
namespace bugprone {

/// Block arguments in `dispatch_async()` and `dispatch_after()` are guaranteed
/// to escape. If those blocks capture any pointers with the `noescape`
/// attribute, then we warn the user of their error.
///
/// For the user-facing documentation see:
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-no-escape.html
class NoEscapeCheck : public ClangTidyCheck {
public:
NoEscapeCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.Blocks;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

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

#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NOESCAPECHECK_H
10 changes: 8 additions & 2 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ New checks
result of a memory allocation function (``malloc()``, ``calloc()``,
``realloc()``, ``alloca()``) instead of its argument.

- New :doc:`bugprone-no-escape
<clang-tidy/checks/bugprone-no-escape>` check.

Finds pointers with the ``noescape`` attribute that are captured by an
asynchronously-executed block.

- New :doc:`bugprone-spuriously-wake-up-functions
<clang-tidy/checks/bugprone-spuriously-wake-up-functions>` check.

Expand Down Expand Up @@ -206,14 +212,14 @@ Changes in existing checks
Now checks ``std::basic_string_view`` by default.

- Improved :doc:`readability-else-after-return
<clang-tidy/checks/readability-else-after-return>` check now supports a
<clang-tidy/checks/readability-else-after-return>` check now supports a
`WarnOnConditionVariables` option to control whether to refactor condition
variables where possible.

- Improved :doc:`readability-identifier-naming
<clang-tidy/checks/readability-identifier-naming>` check.

Now able to rename member references in class template definitions with
Now able to rename member references in class template definitions with
explicit access.

- Improved :doc:`readability-qualified-auto
Expand Down
18 changes: 18 additions & 0 deletions clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.. title:: clang-tidy - bugprone-no-escape

bugprone-no-escape
==================

Finds pointers with the ``noescape`` attribute that are captured by an
asynchronously-executed block. The block arguments in ``dispatch_async()`` and
``dispatch_after()`` are guaranteed to escape, so it is an error if a pointer with the
``noescape`` attribute is captured by one of these blocks.

The following is an example of an invalid use of the ``noescape`` attribute.

.. code-block:: objc
void foo(__attribute__((noescape)) int *p) {
dispatch_async(queue, ^{
*p = 123;
});
});
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 @@ -70,6 +70,7 @@ Clang-Tidy Checks
`bugprone-misplaced-widening-cast <bugprone-misplaced-widening-cast.html>`_,
`bugprone-move-forwarding-reference <bugprone-move-forwarding-reference.html>`_, "Yes"
`bugprone-multiple-statement-macro <bugprone-multiple-statement-macro.html>`_,
`bugprone-no-escape <bugprone-no-escape.html>`_, "Yes"
`bugprone-not-null-terminated-result <bugprone-not-null-terminated-result.html>`_, "Yes"
`bugprone-parent-virtual-call <bugprone-parent-virtual-call.html>`_, "Yes"
`bugprone-posix-return <bugprone-posix-return.html>`_, "Yes"
Expand Down
28 changes: 28 additions & 0 deletions clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// RUN: %check_clang_tidy %s bugprone-no-escape %t
// RUN: %check_clang_tidy %s -assume-filename=bugprone-no-escape.c bugprone-no-escape %t -- -- -fblocks

typedef struct dispatch_queue_s *dispatch_queue_t;
typedef struct dispatch_time_s *dispatch_time_t;
typedef void (^dispatch_block_t)(void);
void dispatch_async(dispatch_queue_t queue, dispatch_block_t block);
void dispatch_after(dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t block);

extern dispatch_queue_t queue;

void test_noescape_attribute(__attribute__((noescape)) int *p, int *q) {
dispatch_async(queue, ^{
*p = 123;
// CHECK-MESSAGES: :[[@LINE-2]]:25: warning: pointer 'p' with attribute 'noescape' is captured by an asynchronously-executed block [bugprone-no-escape]
// CHECK-MESSAGES: :[[@LINE-4]]:30: note: the 'noescape' attribute is declared here.
});

dispatch_after(456, queue, ^{
*p = 789;
// CHECK-MESSAGES: :[[@LINE-2]]:30: warning: pointer 'p' with attribute 'noescape' is captured by an asynchronously-executed block [bugprone-no-escape]
});

dispatch_async(queue, ^{
*q = 0;
// CHECK-MESSAGES-NOT: :[[@LINE-2]]:25: warning: pointer 'q' with attribute 'noescape' is captured by an asynchronously-executed block
});
}
5 changes: 5 additions & 0 deletions clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,11 @@ def ObjCSignedCharBool : DiagGroup<"objc-signed-char-bool",
ObjCBoolConstantConversion,
TautologicalObjCBoolCompare]>;

def ObjCPotentiallyDirectSelector : DiagGroup<"potentially-direct-selector">;
def ObjCStrictPotentiallyDirectSelector :
DiagGroup<"strict-potentially-direct-selector",
[ObjCPotentiallyDirectSelector]>;

// Inline ASM warnings.
def ASMOperandWidths : DiagGroup<"asm-operand-widths">;
def ASM : DiagGroup<"asm", [
Expand Down
8 changes: 7 additions & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -1378,8 +1378,14 @@ def warn_multiple_selectors: Warning<
"several methods with selector %0 of mismatched types are found "
"for the @selector expression">,
InGroup<SelectorTypeMismatch>, DefaultIgnore;
def err_direct_selector_expression: Error<
def err_direct_selector_expression : Error<
"@selector expression formed with direct selector %0">;
def warn_potentially_direct_selector_expression : Warning<
"@selector expression formed with potentially direct selector %0">,
InGroup<ObjCPotentiallyDirectSelector>;
def warn_strict_potentially_direct_selector_expression : Warning<
warn_potentially_direct_selector_expression.Text>,
InGroup<ObjCStrictPotentiallyDirectSelector>, DefaultIgnore;

def err_objc_kindof_nonobject : Error<
"'__kindof' specifier cannot be applied to non-object type %0">;
Expand Down
5 changes: 3 additions & 2 deletions clang/lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ static RValue EmitBinaryAtomicPost(CodeGenFunction &CGF,
Kind, Args[0], Args[1], llvm::AtomicOrdering::SequentiallyConsistent);
Result = CGF.Builder.CreateBinOp(Op, Result, Args[1]);
if (Invert)
Result = CGF.Builder.CreateBinOp(llvm::Instruction::Xor, Result,
llvm::ConstantInt::get(IntType, -1));
Result =
CGF.Builder.CreateBinOp(llvm::Instruction::Xor, Result,
llvm::ConstantInt::getAllOnesValue(IntType));
Result = EmitFromInt(CGF, Result, T, ValueType);
return RValue::get(Result);
}
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/Driver/ToolChains/HIP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ void AMDGCN::Linker::constructGenerateObjFileFromHIPFatBinary(

Objf << ObjBuffer;

ArgStringList McArgs{"-triple", Args.MakeArgString(TC.getTripleString()),
"-o", Output.getFilename(),
ArgStringList McArgs{"-o", Output.getFilename(),
McinFile, "--filetype=obj"};
const char *Mc = Args.MakeArgString(TC.GetProgramPath("llvm-mc"));
C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
Expand Down
18 changes: 11 additions & 7 deletions clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11936,27 +11936,31 @@ static void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
}
}

static void CheckConditionalOperator(Sema &S, ConditionalOperator *E,
static void CheckConditionalOperator(Sema &S, AbstractConditionalOperator *E,
SourceLocation CC, QualType T);

static void CheckConditionalOperand(Sema &S, Expr *E, QualType T,
SourceLocation CC, bool &ICContext) {
E = E->IgnoreParenImpCasts();

if (isa<ConditionalOperator>(E))
return CheckConditionalOperator(S, cast<ConditionalOperator>(E), CC, T);
if (auto *CO = dyn_cast<AbstractConditionalOperator>(E))
return CheckConditionalOperator(S, CO, CC, T);

AnalyzeImplicitConversions(S, E, CC);
if (E->getType() != T)
return CheckImplicitConversion(S, E, T, CC, &ICContext);
}

static void CheckConditionalOperator(Sema &S, ConditionalOperator *E,
static void CheckConditionalOperator(Sema &S, AbstractConditionalOperator *E,
SourceLocation CC, QualType T) {
AnalyzeImplicitConversions(S, E->getCond(), E->getQuestionLoc());

Expr *TrueExpr = E->getTrueExpr();
if (auto *BCO = dyn_cast<BinaryConditionalOperator>(E))
TrueExpr = BCO->getCommon();

bool Suspicious = false;
CheckConditionalOperand(S, E->getTrueExpr(), T, CC, Suspicious);
CheckConditionalOperand(S, TrueExpr, T, CC, Suspicious);
CheckConditionalOperand(S, E->getFalseExpr(), T, CC, Suspicious);

if (T->isBooleanType())
Expand All @@ -11975,7 +11979,7 @@ static void CheckConditionalOperator(Sema &S, ConditionalOperator *E,
if (E->getType() == T) return;

Suspicious = false;
CheckImplicitConversion(S, E->getTrueExpr()->IgnoreParenImpCasts(),
CheckImplicitConversion(S, TrueExpr->IgnoreParenImpCasts(),
E->getType(), CC, &Suspicious);
if (!Suspicious)
CheckImplicitConversion(S, E->getFalseExpr()->IgnoreParenImpCasts(),
Expand Down Expand Up @@ -12038,7 +12042,7 @@ static void AnalyzeImplicitConversions(

// For conditional operators, we analyze the arguments as if they
// were being fed directly into the output.
if (auto *CO = dyn_cast<ConditionalOperator>(SourceExpr)) {
if (auto *CO = dyn_cast<AbstractConditionalOperator>(SourceExpr)) {
CheckConditionalOperator(S, CO, CC, T);
return;
}
Expand Down
Loading

0 comments on commit cba70fe

Please sign in to comment.