diff --git a/llvm/utils/gn/build/BUILD.gn b/llvm/utils/gn/build/BUILD.gn --- a/llvm/utils/gn/build/BUILD.gn +++ b/llvm/utils/gn/build/BUILD.gn @@ -235,6 +235,27 @@ ] } } + + 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") { diff --git a/llvm/utils/gn/build/buildflags.gni b/llvm/utils/gn/build/buildflags.gni --- a/llvm/utils/gn/build/buildflags.gni +++ b/llvm/utils/gn/build/buildflags.gni @@ -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.