[LLVMbugs] [Bug 20277] New: Incorrect macro expansion in clang on Windows with VC++ target

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jul 9 17:06:59 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=20277

            Bug ID: 20277
           Summary: Incorrect macro expansion in clang on Windows with
                    VC++ target
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows XP
            Status: NEW
          Severity: normal
          Priority: P
         Component: Driver
          Assignee: unassignedclangbugs at nondot.org
          Reporter: eldlistmailingz at tropicsoft.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Clang is not doing macro expansion correctly in an instance which I will show.
The build is clang on Windows targeting VC++ built from the latest trunk. The
source is:

# define REM(...) __VA_ARGS__
# define EAT(...)
# define CAT(a, b) CAT_I(a, b)
# define CAT_I(a, b) a ## b
# define LPAREN() (
# define RPAREN() )
# define COMMA() ,
# define STL(seq) STL_I(SBT(seq))
# define STL_I(bseq) STL_A bseq NIL STL_B bseq
# define STL_A(m, e) m(LPAREN() e COMMA() STL_A_ID)
# define STL_A_ID() STL_A
# define STL_B(m, e) m(RPAREN() STL_B_ID)
# define STL_B_ID() STL_B
# define SBT(seq) CAT(SBT_A seq, 0)
# define SBT_A(...) (SBT_GET_REM(__VA_ARGS__), __VA_ARGS__)() SBT_B
# define SBT_B(...) (SBT_GET_REM(__VA_ARGS__), __VA_ARGS__)() SBT_A
# define SBT_GET_REM(...) REM
# define SBT_A0 (EAT, ?)
# define SBT_B0 (EAT, ?)

int main()
{
STL(())
return 0;
}

The expansion of STL should be:

(,BOOST_PP_NIL)

Admittedly placed in a CPP main function this should lead to a compiler error
etc. since '(, BOOST_PP_NIL )' by itself as C++ is invalid, but I have included
it in this way to keep things simple and to show that the macro expansion
itself is valid. The point is that clang.exe gives these errors trying to
expand the macro:

-------------------------------------------------------------------------------

seq_clang_failure.cpp(23,1) :  error: too few arguments provided to
function-like macro invocation
STL(())
^
seq_clang_failure.cpp(8,25) :  note: expanded from macro 'STL'
# define STL(seq) STL_I(SBT(seq))
                        ^
seq_clang_failure.cpp(14,23) :  note: expanded from macro 'SBT'
# define SBT(seq) CAT(SBT_A seq, 0)
                      ^
seq_clang_failure.cpp(15,59) :  note: expanded from macro 'SBT_A'
# define SBT_A(...) (SBT_GET_REM(__VA_ARGS__), __VA_ARGS__)() SBT_B
                                                          ^
seq_clang_failure.cpp(3,26) :  note: expanded from macro 'CAT'
# define CAT(a, b) CAT_I(a, b)
                         ^
seq_clang_failure.cpp(4,22) :  note: expanded from macro 'CAT_I'
# define CAT_I(a, b) a ## b
                     ^
seq_clang_failure.cpp(9,28) :  note: expanded from macro 'STL_I'
# define STL_I(bseq) STL_A bseq NIL STL_B bseq
                           ^
seq_clang_failure.cpp(10,10) :  note: macro 'STL_A' defined here
# define STL_A(m, e) m(LPAREN() e COMMA() STL_A_ID)
         ^
seq_clang_failure.cpp(23,1) :  error: use of undeclared identifier 'STL_A'
STL(())
^
seq_clang_failure.cpp(8,19) :  note: expanded from macro 'STL'
# define STL(seq) STL_I(SBT(seq))
                  ^
seq_clang_failure.cpp(9,22) :  note: expanded from macro 'STL_I'
# define STL_I(bseq) STL_A bseq NIL STL_B bseq
                     ^
seq_clang_failure.cpp(23,1) :  error: use of undeclared identifier 'EAT'
seq_clang_failure.cpp(8,25) :  note: expanded from macro 'STL'
# define STL(seq) STL_I(SBT(seq))
                        ^
seq_clang_failure.cpp(14,19) :  note: expanded from macro 'SBT'
# define SBT(seq) CAT(SBT_A seq, 0)
                  ^
seq_clang_failure.cpp(3,20) :  note: expanded from macro 'CAT'
# define CAT(a, b) CAT_I(a, b)
                   ^
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see
all)
<scratch space>(2,1) :  note: expanded from here
SBT_B0
^
seq_clang_failure.cpp(19,18) :  note: expanded from macro 'SBT_B0'
# define SBT_B0 (EAT, ?)
                 ^
seq_clang_failure.cpp(9,28) :  note: expanded from macro 'STL_I'
# define STL_I(bseq) STL_A bseq NIL STL_B bseq
                           ^
seq_clang_failure.cpp(23,1) :  error: too few arguments provided to
function-like macro invocation
seq_clang_failure.cpp(8,25) :  note: expanded from macro 'STL'
# define STL(seq) STL_I(SBT(seq))
                        ^
seq_clang_failure.cpp(14,23) :  note: expanded from macro 'SBT'
# define SBT(seq) CAT(SBT_A seq, 0)
                      ^
seq_clang_failure.cpp(15,59) :  note: expanded from macro 'SBT_A'
# define SBT_A(...) (SBT_GET_REM(__VA_ARGS__), __VA_ARGS__)() SBT_B
                                                          ^
seq_clang_failure.cpp(3,26) :  note: expanded from macro 'CAT'
# define CAT(a, b) CAT_I(a, b)
                         ^
seq_clang_failure.cpp(4,22) :  note: expanded from macro 'CAT_I'
# define CAT_I(a, b) a ## b
                     ^
seq_clang_failure.cpp(9,43) :  note: expanded from macro 'STL_I'
# define STL_I(bseq) STL_A bseq NIL STL_B bseq
                                          ^
seq_clang_failure.cpp(12,10) :  note: macro 'STL_B' defined here
# define STL_B(m, e) m(RPAREN() STL_B_ID)
         ^

------------------------------------------------------------------------------

The code is actually taken from Boost PP from the BOOST_PP_SEQ_TO_LIST
functionality when using clang. I have simplified its presentation as a bug 
for convenience. A '()' is a valid Boost PP seq and '(,BOOST_PP_NIL)' is a
valid Boost PP list. The STL macro is just my shorthand for the actual
BOOST_PP_SEQ_TO_LIST.

This is a serious bug. Doing straightforward macro expansion should not fail in
clang. The macro expansion exceeds in all versions of gcc, as well as in the
Boost Wave driver. So unless clang know something that I do not know about
macro expansion in the latest C++, this needs to be fixed.

The command line parameters are:

-TP /Od /Ob0 /W3 /GR /MDd  /Zc:forScope /Zc:wchar_t -fmsc-version=1800 /wd4675
/EHs -c

This is being compiled by the Boost Build system on Windows 7 Ultimate SP1,
with the latest clang.exe built successfully in Visual Studio 2012 using the
release build.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140710/8f4d8844/attachment.html>


More information about the llvm-bugs mailing list