Page MenuHomePhabricator

[clang-tidy] Crash fix for bugprone-misplaced-pointer-arithmetic-in-alloc
ClosedPublic

Authored by baloghadamsoftware on Sep 15 2020, 4:06 AM.

Details

Summary

Placement new operators on non-object types cause crash in bugprone-misplaced-pointer-arithmetic-in-alloc. This patch fixes this issue.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptSep 15 2020, 4:06 AM
baloghadamsoftware requested review of this revision.Sep 15 2020, 4:06 AM
This revision is now accepted and ready to land.Sep 15 2020, 5:16 AM

Please fix the test case first, can't call operator new(unsigned long, void*) with an argument of type void*
The other failures the pre merge bot detected can safely be disregarded

Please fix the test case first, can't call operator new(unsigned long, void*) with an argument of type void*
The other failures the pre merge bot detected can safely be disregarded

Placement new is defined per standard:

void* operator new  ( std::size_t count, void* ptr );

Here, the problem is that size_t is unsigned long on Linux and it seems that it is unsigned long long on Windows. How should I overcome this?

Please fix the test case first, can't call operator new(unsigned long, void*) with an argument of type void*
The other failures the pre merge bot detected can safely be disregarded

Placement new is defined per standard:

void* operator new  ( std::size_t count, void* ptr );

Here, the problem is that size_t is unsigned long on Linux and it seems that it is unsigned long long on Windows. How should I overcome this?

In CSA, to overcome the platform problem, it is common to add a target triple for the RUN line:
https://github.com/llvm/llvm-project/blob/master/clang/test/Analysis/std-c-library-functions.c#L14

Please fix the test case first, can't call operator new(unsigned long, void*) with an argument of type void*
The other failures the pre merge bot detected can safely be disregarded

Placement new is defined per standard:

void* operator new  ( std::size_t count, void* ptr );

Here, the problem is that size_t is unsigned long on Linux and it seems that it is unsigned long long on Windows. How should I overcome this?

In CSA, to overcome the platform problem, it is common to add a target triple for the RUN line:
https://github.com/llvm/llvm-project/blob/master/clang/test/Analysis/std-c-library-functions.c#L14

Please make the tests generic if possible:

typedef decltype(sizeof(void*)) size_t;

std::size_t defined correctly in the tests.