CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
137 lines
3.2 KiB
C++
137 lines
3.2 KiB
C++
// RUN: %clang_analyze_cc1 -std=c++14 \
|
|
// RUN: -analyzer-checker=core.CallAndMessage \
|
|
// RUN: -analyzer-config suppress-null-return-paths=false \
|
|
// RUN: -verify %s
|
|
// RUN: %clang_analyze_cc1 -std=c++14 \
|
|
// RUN: -analyzer-checker=core.CallAndMessage \
|
|
// RUN: -DSUPPRESSED \
|
|
// RUN: -verify %s
|
|
|
|
#ifdef SUPPRESSED
|
|
// expected-no-diagnostics
|
|
#endif
|
|
|
|
#include <stdint.h>
|
|
#include "../Inputs/system-header-simulator-cxx.h"
|
|
|
|
void error();
|
|
void *malloc(size_t);
|
|
|
|
|
|
// From llvm/include/llvm/Support/MathExtras.h
|
|
inline uintptr_t alignAddr(const void *Addr, size_t Alignment) {
|
|
return (((uintptr_t)Addr + Alignment - 1) & ~(uintptr_t)(Alignment - 1));
|
|
}
|
|
|
|
inline size_t alignmentAdjustment(const void *Ptr, size_t Alignment) {
|
|
return alignAddr(Ptr, Alignment) - (uintptr_t)Ptr;
|
|
}
|
|
|
|
|
|
// From llvm/include/llvm/Support/MemAlloc.h
|
|
inline void *safe_malloc(size_t Sz) {
|
|
void *Result = malloc(Sz);
|
|
if (Result == nullptr)
|
|
error();
|
|
|
|
return Result;
|
|
}
|
|
|
|
|
|
// From llvm/include/llvm/Support/Allocator.h
|
|
class MallocAllocator {
|
|
public:
|
|
void *Allocate(size_t Size, size_t /*Alignment*/) {
|
|
return safe_malloc(Size);
|
|
}
|
|
};
|
|
|
|
class BumpPtrAllocator {
|
|
public:
|
|
void *Allocate(size_t Size, size_t Alignment) {
|
|
BytesAllocated += Size;
|
|
size_t Adjustment = alignmentAdjustment(CurPtr, Alignment);
|
|
size_t SizeToAllocate = Size;
|
|
|
|
size_t PaddedSize = SizeToAllocate + Alignment - 1;
|
|
uintptr_t AlignedAddr = alignAddr(Allocator.Allocate(PaddedSize, 0),
|
|
Alignment);
|
|
char *AlignedPtr = (char*)AlignedAddr;
|
|
|
|
return AlignedPtr;
|
|
}
|
|
|
|
private:
|
|
char *CurPtr = nullptr;
|
|
size_t BytesAllocated = 0;
|
|
MallocAllocator Allocator;
|
|
};
|
|
|
|
|
|
// From clang/include/clang/AST/ASTContextAllocate.h
|
|
class ASTContext;
|
|
|
|
void *operator new(size_t Bytes, const ASTContext &C, size_t Alignment = 8);
|
|
void *operator new[](size_t Bytes, const ASTContext &C, size_t Alignment = 8);
|
|
|
|
|
|
// From clang/include/clang/AST/ASTContext.h
|
|
class ASTContext {
|
|
public:
|
|
void *Allocate(size_t Size, unsigned Align = 8) const {
|
|
return BumpAlloc.Allocate(Size, Align);
|
|
}
|
|
|
|
template <typename T>
|
|
T *Allocate(size_t Num = 1) const {
|
|
return static_cast<T *>(Allocate(Num * sizeof(T), alignof(T)));
|
|
}
|
|
|
|
private:
|
|
mutable BumpPtrAllocator BumpAlloc;
|
|
};
|
|
|
|
|
|
// From clang/include/clang/AST/ASTContext.h
|
|
inline void *operator new(size_t Bytes, const ASTContext &C,
|
|
size_t Alignment /* = 8 */) {
|
|
return C.Allocate(Bytes, Alignment);
|
|
}
|
|
|
|
inline void *operator new[](size_t Bytes, const ASTContext &C,
|
|
size_t Alignment /* = 8 */) {
|
|
return C.Allocate(Bytes, Alignment);
|
|
}
|
|
|
|
|
|
// From clang/include/clang/AST/Attr.h
|
|
void *operator new(size_t Bytes, ASTContext &C,
|
|
size_t Alignment = 8) noexcept {
|
|
return ::operator new(Bytes, C, Alignment);
|
|
}
|
|
|
|
|
|
class A {
|
|
public:
|
|
void setValue(int value) { Value = value; }
|
|
private:
|
|
int Value;
|
|
};
|
|
|
|
void f(const ASTContext &C) {
|
|
A *a = new (C) A;
|
|
a->setValue(13);
|
|
#ifndef SUPPRESSED
|
|
// expected-warning@-2 {{Called C++ object pointer is null}}
|
|
#endif
|
|
}
|
|
|
|
void g(const ASTContext &C) {
|
|
A *a = new (C) A[1];
|
|
a[0].setValue(13);
|
|
#ifndef SUPPRESSED
|
|
// expected-warning@-2 {{Called C++ object pointer is null}}
|
|
#endif
|
|
}
|
|
|