forked from GPUOpen-Drivers/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged master:0d7286a6523 into amd-gfx:7a72f3ba645
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
Showing
60 changed files
with
1,061 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.