decimal_util: do not produce warnings when building with gcc

When I build with gcc5, I get the following warning:

  ../../src/kudu/util/decimal_util.cc:31:45: warning: ‘no_sanitize’ 
attribute directive ignored [-Wattributes]
   int128_t MaxUnscaledDecimal(int8_t precision) {

This is because gcc doesn't recognize the "no_sanitize" attribute, so let's
deal with this as we've dealt with other sanitizer suppressions: compile it
conditionally using ASAN support as a proxy.

Change-Id: Iac9b145a914d551e3a18d62a0984aad34b95f4dd
Reviewed-on: http://gerrit.cloudera.org:8080/9499
Tested-by: Kudu Jenkins
Reviewed-by: Grant Henke <granthe...@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/c8724c61
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/c8724c61
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/c8724c61

Branch: refs/heads/master
Commit: c8724c61501a0e940fbcda6cc4d13716b65f8a8a
Parents: 940e60f
Author: Adar Dembo <a...@cloudera.com>
Authored: Mon Mar 5 14:22:30 2018 -0800
Committer: Adar Dembo <a...@cloudera.com>
Committed: Tue Mar 6 23:09:51 2018 +0000

----------------------------------------------------------------------
 src/kudu/gutil/port.h         | 13 +++++++++++++
 src/kudu/util/decimal_util.cc |  6 ++++--
 2 files changed, 17 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/c8724c61/src/kudu/gutil/port.h
----------------------------------------------------------------------
diff --git a/src/kudu/gutil/port.h b/src/kudu/gutil/port.h
index 900df65..9c66721 100644
--- a/src/kudu/gutil/port.h
+++ b/src/kudu/gutil/port.h
@@ -420,6 +420,19 @@ inline void* memrchr(const void* bytes, int find_char, 
size_t len) {
 #define ATTRIBUTE_NO_SANITIZE_THREAD
 #endif
 
+// Tell UBSAN to ignore a given function completely. There is no
+// __has_feature(undefined_sanitizer) or equivalent, so ASAN support is used as
+// a proxy.
+#if defined(__has_feature)
+#  if __has_feature(address_sanitizer)
+#  define ATTRIBUTE_NO_SANITIZE_UNDEFINED \
+      __attribute__((no_sanitize("undefined")))
+#  endif
+#endif
+#ifndef ATTRIBUTE_NO_SANITIZE_UNDEFINED
+#define ATTRIBUTE_NO_SANITIZE_UNDEFINED
+#endif
+
 // Tell UBSAN to ignore integer overflows in a given function. There is no
 // __has_feature(undefined_sanitizer) or equivalent, so ASAN support is used as
 // a proxy.

http://git-wip-us.apache.org/repos/asf/kudu/blob/c8724c61/src/kudu/util/decimal_util.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/decimal_util.cc b/src/kudu/util/decimal_util.cc
index d4f7e70..0e04494 100644
--- a/src/kudu/util/decimal_util.cc
+++ b/src/kudu/util/decimal_util.cc
@@ -21,13 +21,15 @@
 
 #include <glog/logging.h>
 
+#include "kudu/gutil/port.h"
+
 namespace kudu {
 
 using std::string;
 
 // Workaround for an ASAN build issue documented here:
 // https://bugs.llvm.org/show_bug.cgi?id=16404
-__attribute__((no_sanitize("undefined")))
+ATTRIBUTE_NO_SANITIZE_UNDEFINED
 int128_t MaxUnscaledDecimal(int8_t precision) {
   DCHECK_GE(precision, kMinDecimalPrecision);
   DCHECK_LE(precision, kMaxDecimalPrecision);
@@ -44,7 +46,7 @@ int128_t MinUnscaledDecimal(int8_t precision) {
 
 // Workaround for an ASAN build issue documented here:
 // https://bugs.llvm.org/show_bug.cgi?id=16404
-__attribute__((no_sanitize("undefined")))
+ATTRIBUTE_NO_SANITIZE_UNDEFINED
 string DecimalToString(int128_t d, int8_t scale) {
   // 38 digits, 1 extra leading zero, decimal point,
   // and sign are good for 128-bit or smaller decimals.

Reply via email to