llvm-project/clang/test/Analysis/conditional-path-notes.c
Nico Weber 97c675d3d4 Revert "Revert "Temporarily do not drop volatile stores before unreachable""
This reverts commit 52aeacfbf5ce5f949efe0eae029e56db171ea1f7.
There isn't full agreement on a path forward yet, but there is agreement that
this shouldn't land as-is.  See discussion on https://reviews.llvm.org/D105338

Also reverts unreviewed "[clang] Improve `-Wnull-dereference` diag to be more in-line with reality"
This reverts commit f4877c78c0fc98be47b926439bbfe33d5e1d1b6d.

And all the related changes to tests:
This reverts commit 9a0152799f8e4a59e0483728c9f11c8a7805616f.
This reverts commit 3f7c9cc27422f7302cf5a683eeb3978e6cb84270.
This reverts commit 329f8197ef59f9bd23328b52d623ba768b51dbb2.
This reverts commit aa9f58cc2c48ca6cfc853a2467cd775dc7622746.
This reverts commit 2df37d5ddd38091aafbb7d338660e58836f4ac80.
This reverts commit a72a44181264fd83e05be958c2712cbd4560aba7.
2021-07-09 11:44:34 -04:00

87 lines
3.3 KiB
C

// RUN: %clang_analyze_cc1 %s -analyzer-checker=core.NullDereference -analyzer-output=text -verify
// RUN: %clang_analyze_cc1 %s -analyzer-checker=core.NullDereference -analyzer-output=plist -o %t
// RUN: %normalize_plist <%t | diff -ub %S/Inputs/expected-plists/conditional-path-notes.c.plist -
void testCondOp(int *p) {
int *x = p ? p : p;
// expected-note@-1 {{Assuming 'p' is null}}
// expected-note@-2 {{'?' condition is false}}
// expected-note@-3 {{'x' initialized to a null pointer value}}
*x = 1; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}
// expected-note@-1 {{Dereference of null pointer (loaded from variable 'x')}}
}
void testCondProblem(int *p) {
if (p) return;
// expected-note@-1 {{Assuming 'p' is null}}
// expected-note@-2 {{Taking false branch}}
int x = *p ? 0 : 1; // expected-warning{{Dereference of null pointer (loaded from variable 'p')}}
// expected-note@-1 {{Dereference of null pointer (loaded from variable 'p')}}
(void)x;
}
void testLHSProblem(int *p) {
int x = !p ? *p : 1; // expected-warning{{Dereference of null pointer (loaded from variable 'p')}}
// expected-note@-1 {{Assuming 'p' is null}}
// expected-note@-2 {{'?' condition is true}}
// expected-note@-3 {{Dereference of null pointer (loaded from variable 'p')}}
(void)x;
}
void testRHSProblem(int *p) {
int x = p ? 1 : *p; // expected-warning{{Dereference of null pointer (loaded from variable 'p')}}
// expected-note@-1 {{Assuming 'p' is null}}
// expected-note@-2 {{'?' condition is false}}
// expected-note@-3 {{Dereference of null pointer (loaded from variable 'p')}}
(void)x;
}
void testBinaryCondOp(int *p) {
int *x = p ?: p;
// expected-note@-1 {{'?' condition is false}}
// expected-note@-2 {{'x' initialized to a null pointer value}}
*x = 1; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}
// expected-note@-1 {{Dereference of null pointer (loaded from variable 'x')}}
}
void testBinaryLHSProblem(int *p) {
if (p) return;
// expected-note@-1 {{Assuming 'p' is null}}
// expected-note@-2 {{Taking false branch}}
int x = *p ?: 1; // expected-warning{{Dereference of null pointer (loaded from variable 'p')}}
// expected-note@-1 {{Dereference of null pointer (loaded from variable 'p')}}
(void)x;
}
void testDiagnosableBranch(int a) {
if (a) {
// expected-note@-1 {{Assuming 'a' is not equal to 0}}
// expected-note@-2 {{Taking true branch}}
*(volatile int *)0 = 1; // expected-warning{{Dereference of null pointer}}
// expected-note@-1 {{Dereference of null pointer}}
}
}
void testDiagnosableBranchLogical(int a, int b) {
if (a && b) {
// expected-note@-1 {{Assuming 'a' is not equal to 0}}
// expected-note@-2 {{Left side of '&&' is true}}
// expected-note@-3 {{Assuming 'b' is not equal to 0}}
// expected-note@-4 {{Taking true branch}}
*(volatile int *)0 = 1; // expected-warning{{Dereference of null pointer}}
// expected-note@-1 {{Dereference of null pointer}}
}
}
void testNonDiagnosableBranchArithmetic(int a, int b) {
if (a - b) {
// expected-note@-1 {{Taking true branch}}
// expected-note@-2 {{Assuming the condition is true}}
*(volatile int *)0 = 1; // expected-warning{{Dereference of null pointer}}
// expected-note@-1 {{Dereference of null pointer}}
}
}