llvm-capstone/clang/test/SemaObjC/attr-suppress.m
Artem Dergachev ef3f476097 [attributes][analyzer] Implement [[clang::suppress]] - suppress static analysis warnings.
The new attribute can be placed on statements in order to suppress
arbitrary warnings produced by static analysis tools at those statements.

Previously such suppressions were implemented as either informal comments
(eg. clang-tidy `// NOLINT:`) or with preprocessor macros (eg.
clang static analyzer's `#ifdef __clang_analyzer__`). The attribute
provides a universal, formal, flexible and neat-looking suppression mechanism.

Implement support for the new attribute in the clang static analyzer;
clang-tidy coming soon.

The attribute allows specifying which specific warnings to suppress,
in the form of free-form strings that are intended to be specific to
the tools, but currently none are actually supported; so this is also
going to be a future improvement.

Differential Revision: https://reviews.llvm.org/D93110
2023-12-13 18:09:16 -08:00

51 lines
1.5 KiB
Objective-C

// RUN: %clang_cc1 -fsyntax-only -fblocks %s -verify
#define SUPPRESS1 __attribute__((suppress))
#define SUPPRESS2(...) __attribute__((suppress(__VA_ARGS__)))
SUPPRESS1 int global = 42;
SUPPRESS1 void foo() {
// expected-error@-1 {{'suppress' attribute only applies to variables and statements}}
SUPPRESS1 int *p;
SUPPRESS1 int a = 0; // no-warning
SUPPRESS2()
int b = 1; // no-warning
SUPPRESS2("a")
int c = a + b; // no-warning
SUPPRESS2("a", "b") { b = c - a; } // no-warning
SUPPRESS2("a", "b")
if (b == 10)
a += 4; // no-warning
SUPPRESS1 while (1) {} // no-warning
SUPPRESS1 switch (a) { // no-warning
default:
c -= 10;
}
// GNU-style attributes and C++11 attributes apply to different things when
// written like this. GNU attribute gets attached to the declaration, while
// C++11 attribute ends up on the type.
int SUPPRESS2("r") z;
SUPPRESS2(foo)
float f;
// expected-error@-2 {{expected string literal as argument of 'suppress' attribute}}
}
union SUPPRESS2("type.1") U {
// expected-error@-1 {{'suppress' attribute only applies to variables and statements}}
int i;
float f;
};
SUPPRESS1 @interface Test {
// expected-error@-1 {{'suppress' attribute only applies to variables and statements}}
}
@property SUPPRESS2("prop") int *prop;
// expected-error@-1 {{'suppress' attribute only applies to variables and statements}}
- (void)bar:(int)x SUPPRESS1;
// expected-error@-1 {{'suppress' attribute only applies to variables and statements}}
@end