-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Functions like `operator new` and `operator delete` carry a hidden attribute `__attribute__((visibility("default")))` which has no valid `SourceLocation` as it is inherited from the STL. This patch adds code to use only a valid `SourceLocation` to apply the offset to it to get the replacement range of the `FunctionDecl`.
- Loading branch information
1 parent
3d964b4
commit 2b9be10
Showing
3 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <cstdio> | ||
#include <cstdlib> | ||
|
||
// replacement of a minimal set of functions: | ||
void* operator new(std::size_t sz) { | ||
std::printf("global op new called, size = %zu\n",sz); | ||
return std::malloc(sz); | ||
} | ||
void operator delete(void* ptr) noexcept | ||
{ | ||
std::puts("global op delete called"); | ||
std::free(ptr); | ||
} | ||
int main() { | ||
int* p1 = new int; | ||
delete p1; | ||
|
||
int* p2 = new int[10]; // guaranteed to call the replacement in C++11 | ||
delete[] p2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <cstdio> | ||
#include <cstdlib> | ||
|
||
// replacement of a minimal set of functions: | ||
__attribute__((visibility("default"))) void * operator new(std::size_t sz) | ||
{ | ||
printf("global op new called, size = %zu\n", sz); | ||
return malloc(sz); | ||
} | ||
|
||
__attribute__((visibility("default"))) void operator delete(void * ptr) noexcept | ||
{ | ||
puts("global op delete called"); | ||
free(ptr); | ||
} | ||
|
||
int main() | ||
{ | ||
int * p1 = new int; | ||
delete p1; | ||
int * p2 = new int[10]; | ||
delete[] p2; | ||
} | ||
|