Skip to content

Commit 136afd1

Browse files
committed
Merge from 'main' to 'sycl-web' (7 commits)
CONFLICT (content): Merge conflict in clang/lib/Driver/Driver.cpp
2 parents 9269482 + 937aaea commit 136afd1

File tree

82 files changed

+2866
-3775
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+2866
-3775
lines changed

clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,35 @@ using namespace clang::ast_matchers;
1616
using clang::tidy::utils::hasPtrOrReferenceInFunc;
1717

1818
namespace clang {
19+
namespace ast_matchers {
20+
/// matches a Decl if it has a "no return" attribute of any kind
21+
AST_MATCHER(Decl, declHasNoReturnAttr) {
22+
return Node.hasAttr<NoReturnAttr>() || Node.hasAttr<CXX11NoReturnAttr>() ||
23+
Node.hasAttr<C11NoReturnAttr>();
24+
}
25+
26+
/// matches a FunctionType if the type includes the GNU no return attribute
27+
AST_MATCHER(FunctionType, typeHasNoReturnAttr) {
28+
return Node.getNoReturnAttr();
29+
}
30+
} // namespace ast_matchers
1931
namespace tidy {
2032
namespace bugprone {
2133

2234
static internal::Matcher<Stmt>
2335
loopEndingStmt(internal::Matcher<Stmt> Internal) {
24-
// FIXME: Cover noreturn ObjC methods (and blocks?).
36+
internal::Matcher<QualType> isNoReturnFunType =
37+
ignoringParens(functionType(typeHasNoReturnAttr()));
38+
internal::Matcher<Decl> isNoReturnDecl =
39+
anyOf(declHasNoReturnAttr(), functionDecl(hasType(isNoReturnFunType)),
40+
varDecl(hasType(blockPointerType(pointee(isNoReturnFunType)))));
41+
2542
return stmt(anyOf(
2643
mapAnyOf(breakStmt, returnStmt, gotoStmt, cxxThrowExpr).with(Internal),
27-
callExpr(Internal, callee(functionDecl(isNoReturn())))));
44+
callExpr(Internal,
45+
callee(mapAnyOf(functionDecl, /* block callee */ varDecl)
46+
.with(isNoReturnDecl))),
47+
objcMessageExpr(Internal, callee(isNoReturnDecl))));
2848
}
2949

3050
/// Return whether `Var` was changed in `LoopStmt`.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// RUN: %check_clang_tidy %s bugprone-infinite-loop %t -- -- -fblocks -fexceptions
2+
// RUN: %check_clang_tidy %s bugprone-infinite-loop %t -- -- -fblocks -fobjc-arc -fexceptions
3+
4+
@interface I
5+
+ (void)foo;
6+
+ (void)bar;
7+
+ (void)baz __attribute__((noreturn));
8+
+ (instancetype)alloc;
9+
- (instancetype)init;
10+
@end
11+
12+
_Noreturn void term();
13+
14+
void plainCFunction() {
15+
int i = 0;
16+
int j = 0;
17+
int a[10];
18+
19+
while (i < 10) {
20+
// no warning, function term has C noreturn attribute
21+
term();
22+
}
23+
while (i < 10) {
24+
// no warning, class method baz has noreturn attribute
25+
[I baz];
26+
}
27+
while (i + j < 10) {
28+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i, j) are updated in the loop body [bugprone-infinite-loop]
29+
[I foo];
30+
}
31+
while (i + j < 10) {
32+
[I foo];
33+
[I baz]; // no warning, class method baz has noreturn attribute
34+
}
35+
36+
void (^block)() = ^{
37+
};
38+
void __attribute__((noreturn)) (^block_nr)(void) = ^void __attribute__((noreturn)) (void) { throw "err"; };
39+
40+
while (i < 10) {
41+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i) are updated in the loop body [bugprone-infinite-loop]
42+
block();
43+
}
44+
while (i < 10) {
45+
// no warning, the block has "noreturn" arribute
46+
block_nr();
47+
}
48+
}
49+
50+
@implementation I
51+
+ (void)bar {
52+
}
53+
54+
+ (void)foo {
55+
static int i = 0;
56+
57+
while (i < 10) {
58+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i) are updated in the loop body [bugprone-infinite-loop]
59+
[I bar];
60+
}
61+
}
62+
@end

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,7 @@ void NVPTX::getNVPTXTargetFeatures(const Driver &D, const llvm::Triple &Triple,
693693
/// together object files from the assembler into a single blob.
694694

695695
CudaToolChain::CudaToolChain(const Driver &D, const llvm::Triple &Triple,
696-
const ToolChain &HostTC, const ArgList &Args,
697-
const Action::OffloadKind OK)
696+
const ToolChain &HostTC, const ArgList &Args, const Action::OffloadKind OK)
698697
: ToolChain(D, Triple, Args), HostTC(HostTC),
699698
CudaInstallation(D, HostTC.getTriple(), Args), OK(OK) {
700699
if (CudaInstallation.isValid()) {

0 commit comments

Comments
 (0)