diff options
author | Reid Kleckner <rnk@google.com> | 2019-12-22 13:25:24 -0800 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2019-12-23 10:02:01 -0800 |
commit | a9fdfe63ce023b5aff0fb160375dd28eabf525df (patch) | |
tree | b9f1338781b2967cb5bc96c241fda8c0411cae95 /llvm/lib/Support/CommandLine.cpp | |
parent | e7d5131d3b122cdae5442b02f60e8527423c40c3 (diff) | |
download | llvm-a9fdfe63ce023b5aff0fb160375dd28eabf525df.zip llvm-a9fdfe63ce023b5aff0fb160375dd28eabf525df.tar.gz llvm-a9fdfe63ce023b5aff0fb160375dd28eabf525df.tar.bz2 |
Fix LLVM tool --version build mode printing for MSVC
LLVM tools such as llc print "DEBUG build" or "Optimized build" when
passed --version. Before this change, this was implemented by checking
for the __OPTIMIZE__ GCC macro. MSVC does not define this macro. For
MSVC, control this behavior with _DEBUG instead. It doesn't have
precisely the same meaning, but in most configurations, it will do the
right thing.
Fixes PR17752
Reviewed by: MaskRay
Differential Revision: https://reviews.llvm.org/D71817
Diffstat (limited to 'llvm/lib/Support/CommandLine.cpp')
-rw-r--r-- | llvm/lib/Support/CommandLine.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index ce14634..e4e2f00 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -2436,6 +2436,28 @@ static VersionPrinterTy OverrideVersionPrinter = nullptr; static std::vector<VersionPrinterTy> *ExtraVersionPrinters = nullptr; +#if defined(__GNUC__) +// GCC and GCC-compatible compilers define __OPTIMIZE__ when optimizations are +// enabled. +# if defined(__OPTIMIZE__) +# define LLVM_IS_DEBUG_BUILD 0 +# else +# define LLVM_IS_DEBUG_BUILD 1 +# endif +#elif defined(_MSC_VER) +// MSVC doesn't have a predefined macro indicating if optimizations are enabled. +// Use _DEBUG instead. This macro actually corresponds to the choice between +// debug and release CRTs, but it is a reasonable proxy. +# if defined(_DEBUG) +# define LLVM_IS_DEBUG_BUILD 1 +# else +# define LLVM_IS_DEBUG_BUILD 0 +# endif +#else +// Otherwise, for an unknown compiler, assume this is an optimized build. +# define LLVM_IS_DEBUG_BUILD 0 +#endif + namespace { class VersionPrinter { public: @@ -2451,7 +2473,7 @@ public: OS << " " << LLVM_VERSION_INFO; #endif OS << "\n "; -#ifndef __OPTIMIZE__ +#if LLVM_IS_DEBUG_BUILD OS << "DEBUG build"; #else OS << "Optimized build"; |