[clang-cl] Ignore /Wv and /Wv:17 flags
[llvm-project.git] / clang / test / Analysis / inlining / placement-new-fp-suppression.cpp
blob5a99ad11cc17ed0705e09cce07d28abb018f8fb4
1 // RUN: %clang_analyze_cc1 -std=c++14 \
2 // RUN: -analyzer-checker=core.CallAndMessage \
3 // RUN: -analyzer-config suppress-null-return-paths=false \
4 // RUN: -verify %s
5 // RUN: %clang_analyze_cc1 -std=c++14 \
6 // RUN: -analyzer-checker=core.CallAndMessage \
7 // RUN: -DSUPPRESSED \
8 // RUN: -verify %s
10 #ifdef SUPPRESSED
11 // expected-no-diagnostics
12 #endif
14 #include <stdint.h>
15 #include "../Inputs/system-header-simulator-cxx.h"
17 void error();
18 void *malloc(size_t);
21 // From llvm/include/llvm/Support/MathExtras.h
22 inline uintptr_t alignAddr(const void *Addr, size_t Alignment) {
23 return (((uintptr_t)Addr + Alignment - 1) & ~(uintptr_t)(Alignment - 1));
26 inline size_t alignmentAdjustment(const void *Ptr, size_t Alignment) {
27 return alignAddr(Ptr, Alignment) - (uintptr_t)Ptr;
31 // From llvm/include/llvm/Support/MemAlloc.h
32 inline void *safe_malloc(size_t Sz) {
33 void *Result = malloc(Sz);
34 if (Result == nullptr)
35 error();
37 return Result;
41 // From llvm/include/llvm/Support/Allocator.h
42 class MallocAllocator {
43 public:
44 void *Allocate(size_t Size, size_t /*Alignment*/) {
45 return safe_malloc(Size);
49 class BumpPtrAllocator {
50 public:
51 void *Allocate(size_t Size, size_t Alignment) {
52 BytesAllocated += Size;
53 size_t Adjustment = alignmentAdjustment(CurPtr, Alignment);
54 size_t SizeToAllocate = Size;
56 size_t PaddedSize = SizeToAllocate + Alignment - 1;
57 uintptr_t AlignedAddr = alignAddr(Allocator.Allocate(PaddedSize, 0),
58 Alignment);
59 char *AlignedPtr = (char*)AlignedAddr;
61 return AlignedPtr;
64 private:
65 char *CurPtr = nullptr;
66 size_t BytesAllocated = 0;
67 MallocAllocator Allocator;
71 // From clang/include/clang/AST/ASTContextAllocate.h
72 class ASTContext;
74 void *operator new(size_t Bytes, const ASTContext &C, size_t Alignment = 8);
75 void *operator new[](size_t Bytes, const ASTContext &C, size_t Alignment = 8);
78 // From clang/include/clang/AST/ASTContext.h
79 class ASTContext {
80 public:
81 void *Allocate(size_t Size, unsigned Align = 8) const {
82 return BumpAlloc.Allocate(Size, Align);
85 template <typename T>
86 T *Allocate(size_t Num = 1) const {
87 return static_cast<T *>(Allocate(Num * sizeof(T), alignof(T)));
90 private:
91 mutable BumpPtrAllocator BumpAlloc;
95 // From clang/include/clang/AST/ASTContext.h
96 inline void *operator new(size_t Bytes, const ASTContext &C,
97 size_t Alignment /* = 8 */) {
98 return C.Allocate(Bytes, Alignment);
101 inline void *operator new[](size_t Bytes, const ASTContext &C,
102 size_t Alignment /* = 8 */) {
103 return C.Allocate(Bytes, Alignment);
107 // From clang/include/clang/AST/Attr.h
108 void *operator new(size_t Bytes, ASTContext &C,
109 size_t Alignment = 8) noexcept {
110 return ::operator new(Bytes, C, Alignment);
114 class A {
115 public:
116 void setValue(int value) { Value = value; }
117 private:
118 int Value;
121 void f(const ASTContext &C) {
122 A *a = new (C) A;
123 a->setValue(13);
124 #ifndef SUPPRESSED
125 // expected-warning@-2 {{Called C++ object pointer is null}}
126 #endif
129 void g(const ASTContext &C) {
130 A *a = new (C) A[1];
131 a[0].setValue(13);
132 #ifndef SUPPRESSED
133 // expected-warning@-2 {{Called C++ object pointer is null}}
134 #endif