From 90527cb3249f353ac0f67d923c484ee949e3c939 Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Mon, 14 Apr 2014 11:16:53 +0000 Subject: [PATCH] [asan] don't use bool in public interface, make sure the interface headers are usable in plain C llvm-svn: 206160 --- compiler-rt/include/sanitizer/asan_interface.h | 13 +++++++------ compiler-rt/lib/asan/asan_allocator2.cc | 2 +- compiler-rt/lib/asan/asan_interface_internal.h | 6 +++--- compiler-rt/lib/asan/asan_poisoning.cc | 2 +- compiler-rt/lib/asan/asan_report.cc | 4 ++-- compiler-rt/test/asan/TestCases/interface_test.cc | 2 ++ 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/compiler-rt/include/sanitizer/asan_interface.h b/compiler-rt/include/sanitizer/asan_interface.h index 045ca954b6fa..d244346e4ed4 100644 --- a/compiler-rt/include/sanitizer/asan_interface.h +++ b/compiler-rt/include/sanitizer/asan_interface.h @@ -50,9 +50,10 @@ extern "C" { ((void)(addr), (void)(size)) #endif - // Returns true iff addr is poisoned (i.e. 1-byte read/write access to this + // Returns 1 if addr is poisoned (i.e. 1-byte read/write access to this // address will result in error report from AddressSanitizer). - bool __asan_address_is_poisoned(void const volatile *addr); + // Otherwise returns 0. + int __asan_address_is_poisoned(void const volatile *addr); // If at least on byte in [beg, beg+size) is poisoned, return the address // of the first such byte. Otherwise return 0. @@ -65,7 +66,7 @@ extern "C" { // However it is still a part of the interface because users may want to // set a breakpoint on this function in a debugger. void __asan_report_error(void *pc, void *bp, void *sp, - void *addr, bool is_write, size_t access_size); + void *addr, int is_write, size_t access_size); // Sets the exit code to use when reporting an error. // Returns the old value. @@ -87,9 +88,9 @@ extern "C" { // memory, returns the maximal possible allocation size, otherwise returns // "size". size_t __asan_get_estimated_allocated_size(size_t size); - // Returns true if p was returned by the ASan allocator and - // is not yet freed. - bool __asan_get_ownership(const void *p); + // Returns 1 if p was returned by the ASan allocator and is not yet freed. + // Otherwise returns 0. + int __asan_get_ownership(const void *p); // Returns the number of bytes reserved for the pointer p. // Requires (get_ownership(p) == true) or (p == 0). size_t __asan_get_allocated_size(const void *p); diff --git a/compiler-rt/lib/asan/asan_allocator2.cc b/compiler-rt/lib/asan/asan_allocator2.cc index a759b8e35b92..ea0ffbe1c0e5 100644 --- a/compiler-rt/lib/asan/asan_allocator2.cc +++ b/compiler-rt/lib/asan/asan_allocator2.cc @@ -799,7 +799,7 @@ uptr __asan_get_estimated_allocated_size(uptr size) { return size; } -bool __asan_get_ownership(const void *p) { +int __asan_get_ownership(const void *p) { uptr ptr = reinterpret_cast(p); return (AllocationSize(ptr) > 0); } diff --git a/compiler-rt/lib/asan/asan_interface_internal.h b/compiler-rt/lib/asan/asan_interface_internal.h index 15d4b60ef5cd..ce71eed81107 100644 --- a/compiler-rt/lib/asan/asan_interface_internal.h +++ b/compiler-rt/lib/asan/asan_interface_internal.h @@ -77,7 +77,7 @@ extern "C" { void __asan_unpoison_memory_region(void const volatile *addr, uptr size); SANITIZER_INTERFACE_ATTRIBUTE - bool __asan_address_is_poisoned(void const volatile *addr); + int __asan_address_is_poisoned(void const volatile *addr); SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_region_is_poisoned(uptr beg, uptr size); @@ -87,7 +87,7 @@ extern "C" { SANITIZER_INTERFACE_ATTRIBUTE void __asan_report_error(uptr pc, uptr bp, uptr sp, - uptr addr, bool is_write, uptr access_size); + uptr addr, int is_write, uptr access_size); SANITIZER_INTERFACE_ATTRIBUTE int __asan_set_error_exit_code(int exit_code); @@ -102,7 +102,7 @@ extern "C" { SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_estimated_allocated_size(uptr size); - SANITIZER_INTERFACE_ATTRIBUTE bool __asan_get_ownership(const void *p); + SANITIZER_INTERFACE_ATTRIBUTE int __asan_get_ownership(const void *p); SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_allocated_size(const void *p); SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_current_allocated_bytes(); SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_heap_size(); diff --git a/compiler-rt/lib/asan/asan_poisoning.cc b/compiler-rt/lib/asan/asan_poisoning.cc index 0e1d2baf6ae5..f75ac0a4ed41 100644 --- a/compiler-rt/lib/asan/asan_poisoning.cc +++ b/compiler-rt/lib/asan/asan_poisoning.cc @@ -146,7 +146,7 @@ void __asan_unpoison_memory_region(void const volatile *addr, uptr size) { } } -bool __asan_address_is_poisoned(void const volatile *addr) { +int __asan_address_is_poisoned(void const volatile *addr) { return __asan::AddressIsPoisoned((uptr)addr); } diff --git a/compiler-rt/lib/asan/asan_report.cc b/compiler-rt/lib/asan/asan_report.cc index c50df27cdb0f..9d1742202988 100644 --- a/compiler-rt/lib/asan/asan_report.cc +++ b/compiler-rt/lib/asan/asan_report.cc @@ -797,8 +797,8 @@ void ReportMacCfReallocUnknown( // --------------------------- Interface --------------------- {{{1 using namespace __asan; // NOLINT -void __asan_report_error(uptr pc, uptr bp, uptr sp, - uptr addr, bool is_write, uptr access_size) { +void __asan_report_error(uptr pc, uptr bp, uptr sp, uptr addr, int is_write, + uptr access_size) { ScopedInErrorReport in_report; // Determine the error type. diff --git a/compiler-rt/test/asan/TestCases/interface_test.cc b/compiler-rt/test/asan/TestCases/interface_test.cc index 297b5526e9d9..c7135c15ad2c 100644 --- a/compiler-rt/test/asan/TestCases/interface_test.cc +++ b/compiler-rt/test/asan/TestCases/interface_test.cc @@ -1,6 +1,8 @@ // Check that user may include ASan interface header. // RUN: %clang_asan %s -o %t && %t +// RUN: %clang_asan -x c %s -o %t && %t // RUN: %clang %s -o %t && %t +// RUN: %clang -x c %s -o %t && %t #include int main() {