Files
TheRock/compiler/amd-llvm/clang/test/Analysis/inlining/inline-defensive-checks.m
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

130 lines
3.2 KiB
Objective-C

// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-config suppress-inlined-defensive-checks=true -verify %s
typedef signed char BOOL;
typedef struct objc_class *Class;
typedef struct objc_object {
Class isa;
} *id;
@protocol NSObject - (BOOL)isEqual:(id)object; @end
@interface NSObject <NSObject> {}
+(id)alloc;
+(id)new;
-(id)init;
-(id)autorelease;
-(id)copy;
- (Class)class;
-(id)retain;
@end
// Check that inline defensive checks is triggered for null expressions
// within CompoundLiteralExpr.
typedef union {
struct dispatch_object_s *_do;
struct dispatch_source_s *_ds;
} dispatch_object_t __attribute__((__transparent_union__));
typedef struct dispatch_source_s *dispatch_source_t;
extern __attribute__((visibility("default"))) __attribute__((__nonnull__)) __attribute__((__nothrow__))
void
dispatch_resume(dispatch_object_t object);
@interface AppDelegate : NSObject {
@protected
dispatch_source_t p;
}
@end
@implementation AppDelegate
- (void)updateDeleteTimer {
if (p != ((void*)0))
;
}
- (void)createAndStartDeleteTimer {
[self updateDeleteTimer];
dispatch_resume(p); // no warning
}
@end
// Test nil receiver suppression.
// We only suppress on nil receiver if the nil value is directly causing the bug.
@interface Foo {
@public
int x;
}
- (Foo *)getFooPtr;
@end
Foo *retNil(void) {
return 0;
}
Foo *retInputOrNil(Foo *p) {
if (p)
return p;
return 0;
}
void idc(Foo *p) {
if (p)
;
}
int testNilReceiver(Foo* fPtr) {
if (fPtr)
;
// On a path where fPtr is nil, mem should be nil.
Foo *mem = [fPtr getFooPtr];
return mem->x; // expected-warning {{Access to instance variable 'x' results in a dereference of a null pointer}}
}
int suppressNilReceiverRetNullCond(Foo* fPtr) {
unsigned zero = 0;
fPtr = retInputOrNil(fPtr);
// On a path where fPtr is nzil, mem should be nil.
Foo *mem = [fPtr getFooPtr];
return mem->x;
}
int suppressNilReceiverRetNullCondCast(id fPtr) {
unsigned zero = 0;
fPtr = retInputOrNil(fPtr);
// On a path where fPtr is nzil, mem should be nil.
Foo *mem = ((id)([(Foo*)(fPtr) getFooPtr]));
return mem->x;
}
int dontSuppressNilReceiverRetNullCond(Foo* fPtr) {
unsigned zero = 0;
fPtr = retInputOrNil(fPtr);
// On a path where fPtr is nil, mem should be nil.
// The warning is not suppressed because the receiver being nil is not
// directly related to the value that triggers the warning.
Foo *mem = [fPtr getFooPtr];
if (!mem)
return 5/zero; // expected-warning {{Division by zero}}
return 0;
}
int dontSuppressNilReceiverRetNull(Foo* fPtr) {
unsigned zero = 0;
fPtr = retNil();
// On a path where fPtr is nil, mem should be nil.
// The warning is not suppressed because the receiver being nil is not
// directly related to the value that triggers the warning.
Foo *mem = [fPtr getFooPtr];
if (!mem)
return 5/zero; // expected-warning {{Division by zero}}
return 0;
}
int dontSuppressNilReceiverIDC(Foo* fPtr) {
unsigned zero = 0;
idc(fPtr);
// On a path where fPtr is nil, mem should be nil.
// The warning is not suppressed because the receiver being nil is not
// directly related to the value that triggers the warning.
Foo *mem = [fPtr getFooPtr];
if (!mem)
return 5/zero; // expected-warning {{Division by zero}}
return 0;
}