mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-18 13:16:49 +00:00

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.
105 lines
2.1 KiB
C++
105 lines
2.1 KiB
C++
// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core -analyzer-output=plist-multi-file -o %t.plist -verify -analyzer-config eagerly-assume=false %s
|
|
// RUN: %normalize_plist <%t.plist | diff -ub %S/Inputs/expected-plists/cxx-for-range.cpp.plist -
|
|
|
|
extern void work();
|
|
|
|
void testLoop() {
|
|
int z[] = {1,2};
|
|
for (int y : z) {
|
|
work();
|
|
work();
|
|
if (y == 2)
|
|
*(volatile int *)0 = 1; // expected-warning {{Dereference of null pointer}}
|
|
work();
|
|
work();
|
|
(void)y;
|
|
}
|
|
|
|
*(volatile int *)0 = 1; // no-warning
|
|
}
|
|
|
|
class MagicVector {
|
|
public:
|
|
MagicVector();
|
|
|
|
using iterator = int *;
|
|
|
|
iterator begin() const;
|
|
iterator end() const;
|
|
};
|
|
|
|
MagicVector get(bool fail = false) {
|
|
if (fail)
|
|
*(volatile int *)0 = 1; // expected-warning {{Dereference of null pointer}}
|
|
return MagicVector{};
|
|
}
|
|
|
|
void testLoopOpaqueCollection() {
|
|
for (int y : get()) {
|
|
work();
|
|
work();
|
|
if (y == 2)
|
|
*(volatile int *)0 = 1; // expected-warning {{Dereference of null pointer}}
|
|
work();
|
|
work();
|
|
(void)y;
|
|
}
|
|
|
|
*(volatile int *)0 = 1; // expected-warning {{Dereference of null pointer}}
|
|
}
|
|
|
|
|
|
class MagicVector2 {
|
|
public:
|
|
MagicVector2();
|
|
|
|
class iterator {
|
|
public:
|
|
int operator*() const;
|
|
iterator &operator++();
|
|
bool operator==(const iterator &);
|
|
bool operator!=(const iterator &);
|
|
};
|
|
|
|
iterator begin() const;
|
|
iterator end() const;
|
|
};
|
|
|
|
MagicVector2 get2() {
|
|
return MagicVector2{};
|
|
}
|
|
|
|
void testLoopOpaqueIterator() {
|
|
for (int y : get2()) {
|
|
work();
|
|
work();
|
|
if (y == 2)
|
|
*(volatile int *)0 = 1; // expected-warning {{Dereference of null pointer}}
|
|
work();
|
|
work();
|
|
(void)y;
|
|
}
|
|
|
|
*(volatile int *)0 = 1; // expected-warning {{Dereference of null pointer}}
|
|
}
|
|
|
|
|
|
void testLoopErrorInRange() {
|
|
for (int y : get(true)) { // error inside get()
|
|
work();
|
|
work();
|
|
if (y == 2)
|
|
*(volatile int *)0 = 1; // no-warning
|
|
work();
|
|
work();
|
|
(void)y;
|
|
}
|
|
|
|
*(volatile int *)0 = 1; // no-warning
|
|
}
|
|
|
|
void testForRangeInit() {
|
|
for (int *arr[3] = {nullptr, nullptr, nullptr}; int *p : arr) // expected-warning {{extension}}
|
|
*p = 1; // expected-warning {{Dereference of null pointer}}
|
|
}
|