aboutsummaryrefslogtreecommitdiff
path: root/clang/test/Analysis
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test/Analysis')
-rw-r--r--clang/test/Analysis/analyzer-enabled-checkers.c1
-rw-r--r--clang/test/Analysis/placement-new.cpp32
-rw-r--r--clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c1
3 files changed, 26 insertions, 8 deletions
diff --git a/clang/test/Analysis/analyzer-enabled-checkers.c b/clang/test/Analysis/analyzer-enabled-checkers.c
index a632b70..32afcf3 100644
--- a/clang/test/Analysis/analyzer-enabled-checkers.c
+++ b/clang/test/Analysis/analyzer-enabled-checkers.c
@@ -20,7 +20,6 @@
// CHECK-NEXT: core.NonNullParamChecker
// CHECK-NEXT: core.NonnilStringConstants
// CHECK-NEXT: core.NullDereference
-// CHECK-NEXT: core.StackAddrEscapeBase
// CHECK-NEXT: core.StackAddressEscape
// CHECK-NEXT: core.UndefinedBinaryOperatorResult
// CHECK-NEXT: core.VLASize
diff --git a/clang/test/Analysis/placement-new.cpp b/clang/test/Analysis/placement-new.cpp
index 766b11c..50bbde2 100644
--- a/clang/test/Analysis/placement-new.cpp
+++ b/clang/test/Analysis/placement-new.cpp
@@ -166,10 +166,29 @@ void f1() {
short a;
};
- // bad (not enough space).
+ // On some systems, (notably before MSVC 16.7), a non-allocating placement
+ // array new could allocate more memory than the nominal size of the array.
+
+ // Since CWG 2382 (implemented in MSVC 16.7), overhead was disallowed for non-allocating placement new.
+ // See:
+ // https://learn.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance?view=msvc-170
+ // https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1969r0.html#2382
+
+ // However, as of 17.1, there is a regression when the type comes from a template
+ // parameter where MSVC reintroduces overhead.
+ // See:
+ // https://developercommunity.visualstudio.com/t/10777485
+ // https://godbolt.org/z/E1z1Tsfvj
+
+ // The checker doesn't warn here because this behavior only affects older
+ // MSVC versions (<16.7) or certain specific versions (17.1).
+ // Suppressing warnings avoids false positives on standard-compliant compilers
+ // and modern MSVC versions, but users of affected MSVC versions should be
+ // aware of potential buffer size issues.
+
const unsigned N = 32;
- alignas(S) unsigned char buffer1[sizeof(S) * N]; // expected-note {{'buffer1' initialized here}}
- ::new (buffer1) S[N]; // expected-warning{{Storage provided to placement new is only 64 bytes, whereas the allocated array type requires more space for internal needs}} expected-note 1 {{}}
+ alignas(S) unsigned char buffer1[sizeof(S) * N];
+ ::new (buffer1) S[N]; // no-warning: See comments above
}
void f2() {
@@ -177,10 +196,11 @@ void f2() {
short a;
};
- // maybe ok but we need to warn.
+ // On some systems, placement array new could allocate more memory than the nominal size of the array.
+ // See the comment at f1() above for more details.
const unsigned N = 32;
- alignas(S) unsigned char buffer2[sizeof(S) * N + sizeof(int)]; // expected-note {{'buffer2' initialized here}}
- ::new (buffer2) S[N]; // expected-warning{{68 bytes is possibly not enough for array allocation which requires 64 bytes. Current overhead requires the size of 4 bytes}} expected-note 1 {{}}
+ alignas(S) unsigned char buffer2[sizeof(S) * N + sizeof(int)];
+ ::new (buffer2) S[N]; // no-warning: See comments above
}
} // namespace testArrayTypesAllocation
diff --git a/clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c b/clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
index b388c31..77fa037 100644
--- a/clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
+++ b/clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
@@ -28,7 +28,6 @@
// CHECK-NEXT: core.NonNullParamChecker
// CHECK-NEXT: core.NonnilStringConstants
// CHECK-NEXT: core.NullDereference
-// CHECK-NEXT: core.StackAddrEscapeBase
// CHECK-NEXT: core.StackAddressEscape
// CHECK-NEXT: core.UndefinedBinaryOperatorResult
// CHECK-NEXT: core.VLASize