[RFC][PATCH] gallivm: Avoid conflict with LLVM's definition of DEBUG

Michel Dänzer michel at daenzer.net
Thu May 28 01:09:10 PDT 2015


From: Michel Dänzer <michel.daenzer at amd.com>

Fixes build failure with --enable-debug:

  Compiling src/gallium/auxiliary/gallivm/lp_bld_misc.cpp ...
In file included from llvm/include/llvm/Object/RelocVisitor.h:23:0,
                 from llvm/include/llvm/DebugInfo/DIContext.h:21,
                 from llvm/include/llvm/ExecutionEngine/RuntimeDyld.h:21,
                 from llvm/include/llvm/ExecutionEngine/ExecutionEngine.h:18,
                 from src/gallium/auxiliary/gallivm/lp_bld_misc.cpp:56:
llvm/include/llvm/Support/Debug.h:92:0: warning: "DEBUG" redefined
 #define DEBUG(X) DEBUG_WITH_TYPE(DEBUG_TYPE, X)
 ^
<command-line>:0:0: note: this is the location of the previous definition
<command-line>:0:7: error: expected identifier before numeric constant
llvm/include/llvm/Support/COFF.h:541:5: note: in expansion of macro ‘DEBUG’
     DEBUG,
     ^
<command-line>:0:7: error: expected ‘}’ before numeric constant
llvm/include/llvm/Support/COFF.h:541:5: note: in expansion of macro ‘DEBUG’
     DEBUG,
     ^
<command-line>:0:7: error: expected unqualified-id before numeric constant
llvm/include/llvm/Support/COFF.h:541:5: note: in expansion of macro ‘DEBUG’
     DEBUG,
     ^
In file included from llvm/include/llvm/Object/COFF.h:19:0,
                 from llvm/include/llvm/Object/RelocVisitor.h:20,
                 from llvm/include/llvm/DebugInfo/DIContext.h:21,
                 from llvm/include/llvm/ExecutionEngine/RuntimeDyld.h:21,
                 from llvm/include/llvm/ExecutionEngine/ExecutionEngine.h:18,
                 from src/gallium/auxiliary/gallivm/lp_bld_misc.cpp:56:
llvm/include/llvm/Support/COFF.h:684:1: error: expected declaration before ‘}’ token
 } // End namespace llvm.
 ^

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=90621
Bugzilla: https://llvm.org/bugs/show_bug.cgi?id=23628
Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
---

Mesa/Gallium community: Does this look like a reasonable way to address
this issue?

LLVM community: Is it necessary to expose the LLVM DEBUG macro in public
headers?

 src/gallium/auxiliary/gallivm/lp_bld_misc.cpp | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
index ffed9e6..7763da7 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
+++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
@@ -50,6 +50,14 @@
 
 #include <stddef.h>
 
+/* Save our definition of DEBUG and undefine it to avoid conflict with LLVM's
+ * definition
+ */
+#ifdef DEBUG
+#define MESA_DEBUG DEBUG
+#undef DEBUG
+#endif
+
 #include <llvm-c/Core.h>
 #include <llvm-c/ExecutionEngine.h>
 #include <llvm/Target/TargetOptions.h>
@@ -70,6 +78,12 @@
 #include <llvm/IR/Module.h>
 #include <llvm/Support/CBindingWrapping.h>
 
+/* Undefine LLVM's definition of DEBUG and restore our definition (if any) */
+#undef DEBUG
+#ifdef MESA_DEBUG
+#define DEBUG MESA_DEBUG
+#endif
+
 #include "pipe/p_config.h"
 #include "util/u_debug.h"
 #include "util/u_cpu_detect.h"
-- 
2.1.4





More information about the llvm-commits mailing list