[gn build] Allow option to build with asan/tsan/ubsan
authorArthur Eubanks <aeubanks@google.com>
Mon, 21 Sep 2020 23:28:21 +0000 (16:28 -0700)
committerArthur Eubanks <aeubanks@google.com>
Wed, 23 Sep 2020 18:24:38 +0000 (11:24 -0700)
Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D88056

llvm/utils/gn/build/BUILD.gn
llvm/utils/gn/build/buildflags.gni

index 3c0b905..373d371 100644 (file)
@@ -235,6 +235,27 @@ config("compiler_defaults") {
       ]
     }
   }
+
+  if (use_ubsan) {
+    assert(is_clang && current_os == "linux",
+           "ubsan only supported on Linux/Clang")
+    cflags += [ "-fsanitize=undefined" ]
+    ldflags += [ "-fsanitize=undefined" ]
+  }
+
+  if (use_asan) {
+    assert(is_clang && current_os == "linux",
+           "asan only supported on Linux/Clang")
+    cflags += [ "-fsanitize=address" ]
+    ldflags += [ "-fsanitize=address" ]
+  }
+
+  if (use_tsan) {
+    assert(is_clang && current_os == "linux",
+           "tsan only supported on Linux/Clang")
+    cflags += [ "-fsanitize=thread" ]
+    ldflags += [ "-fsanitize=thread" ]
+  }
 }
 
 config("no_exceptions") {
index eb8ac55..b04eae1 100644 (file)
@@ -1,6 +1,15 @@
 declare_args() {
   # Whether to build with debug information.
   is_debug = false
+
+  # Whether to build with tsan.
+  use_tsan = false
+
+  # Whether to build with ubsan.
+  use_ubsan = false
+
+  # Whether to build with asan.
+  use_asan = false
 }
 
 # args that depend on other args must live in a later declare_args() block.