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

Jose Fonseca jfonseca at vmware.com
Thu May 28 02:39:21 PDT 2015


Hi Michel,

I'm sorry: I hadn't notice your review-request, and just pushed a 
similar fix.

I used push/pop_macro pragma instead. I think it's portable enough (at 
least gcc and msvc support it).  Your's is probable more portable 
though. I'm OK either way.


Like you said, this is a workaround. LLVM's reliance on DEBUG is a bad 
idea, as Mesa is not the only user of that macro -- several Microsoft 
SDKs use DEBUG for the same end --, so it's better not to rely on it.


Jose

On 28/05/15 09:09, Michel Dänzer wrote:
> 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"
>



More information about the mesa-dev mailing list