Files
TheRock/compiler/amd-llvm/clang/test/Analysis/lambdas.mm
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

144 lines
3.1 KiB
Plaintext

// RUN: %clang_analyze_cc1 -std=c++11 -fblocks -Wno-objc-root-class -analyzer-checker=core,deadcode,debug.ExprInspection -analyzer-config inline-lambdas=true -verify %s
int clang_analyzer_eval(int);
@interface Super
- (void)superMethod;
@end
@interface Sub : Super {
int _ivar1;
int _ivar2;
}
@end
@implementation Sub
- (void)callMethodOnSuperInCXXLambda; {
// Explicit capture.
[self]() {
[super superMethod];
}();
// Implicit capture.
[=]() {
[super superMethod];
}();
}
// Make sure to properly handle super-calls when a block captures
// a local variable named 'self'.
- (void)callMethodOnSuperInCXXLambdaWithRedefinedSelf; {
/*__weak*/ Sub *weakSelf = self;
// Implicit capture. (Sema outlaws explicit capture of a redefined self
// and a call to super [which uses the original self]).
[=]() {
Sub *self = weakSelf;
[=]() {
[super superMethod];
}();
}();
}
- (void)swapIvars {
int tmp = _ivar1;
_ivar1 = _ivar2;
_ivar2 = tmp;
}
- (void)callMethodOnSelfInCXXLambda; {
_ivar1 = 7;
_ivar2 = 8;
[self]() {
[self swapIvars];
}();
clang_analyzer_eval(_ivar1 == 8); // expected-warning{{TRUE}}
clang_analyzer_eval(_ivar2 == 7); // expected-warning{{TRUE}}
}
@end
int getValue();
void useValue(int v);
void castToBlockNoDeadStore() {
int v = getValue(); // no-warning
(void)(void(^)())[v]() { // This capture should count as a use, so no dead store warning above.
};
}
void takesBlock(void(^block)());
void passToFunctionTakingBlockNoDeadStore() {
int v = 7; // no-warning
int x = 8; // no-warning
takesBlock([&v, x]() {
(void)v;
});
}
void castToBlockAndInline() {
int result = ((int(^)(int))[](int p) {
return p;
})(7);
clang_analyzer_eval(result == 7); // expected-warning{{TRUE}}
}
void castToBlockWithCaptureAndInline() {
int y = 7;
auto lambda = [y]{ return y; };
int(^block)() = lambda;
int result = block();
clang_analyzer_eval(result == 7); // expected-warning{{TRUE}}
}
void castMutableLambdaToBlock() {
int x = 0;
auto lambda = [x]() mutable {
x = x + 1;
return x;
};
// The block should copy the lambda before capturing.
int(^block)() = lambda;
int r1 = block();
clang_analyzer_eval(r1 == 1); // expected-warning{{TRUE}}
int r2 = block();
clang_analyzer_eval(r2 == 2); // expected-warning{{TRUE}}
// Because block copied the lambda, r3 should be 1.
int r3 = lambda();
clang_analyzer_eval(r3 == 1); // expected-warning{{TRUE}}
// Aliasing the block shouldn't copy the lambda.
int(^blockAlias)() = block;
int r4 = blockAlias();
clang_analyzer_eval(r4 == 3); // expected-warning{{TRUE}}
int r5 = block();
clang_analyzer_eval(r5 == 4); // expected-warning{{TRUE}}
// Another copy of lambda
int(^blockSecondCopy)() = lambda;
int r6 = blockSecondCopy();
clang_analyzer_eval(r6 == 2); // expected-warning{{TRUE}}
}
void castLambdaInLocalBlock() {
// Make sure we don't emit a spurious diagnostic about the address of a block
// escaping in the implicit conversion operator method for lambda-to-block
// conversions.
auto lambda = []{ }; // no-warning
void(^block)() = lambda;
(void)block;
}