[LLVMbugs] [Bug 16371] New: Preprocessor too eager to stringify in assembler-with-cpp mode?

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jun 19 01:55:13 PDT 2013


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

            Bug ID: 16371
           Summary: Preprocessor too eager to stringify in
                    assembler-with-cpp mode?
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: aseipp at pobox.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

While continuing my porting GHC-to-clang work, I have run into a rather odd
discrepancy in the way Clang's preprocessor handles hashes in parameters and
whatnot vs GCC, and I'm not sure if this is a bug or not. :)

Here is a minimal test case vs GCC 4.7.3:

--------------------------------------------------------
$ gcc -E -undef -traditional -x assembler-with-cpp -o - -
#define foo(a,b,c) \
test asdfx# a b c

foo(a,b,c)

foo(a#,b#,c#)
^D
# 1 "<stdin>"
# 1 "<command-line>"
# 1 "<stdin>"



test asdfx# a b c

test asdfx# a# b# c#
$
$ clang -E -undef -traditional -x assembler-with-cpp -o - -  
#define foo(a,b,c) \
test asdfx# a b c

foo(a,b,c)

foo(a#,b#,c#)
^D
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<stdin>" 2



test asdfx"a" b c

test asdfx"a#" b# c#
--------------------------------------------------------

Note the stringification of the first argument. I'm not sure if this
discrepancy is expected, but we force assembler-with-cpp mode in GHC now.
Perhaps this could be alleviated.

As a more extreme test case, consider the test from bug 16363, cut down
slightly (this is Haskell code but the deficiency should be obvious)

GCC:

--------------------------------------------------------
$ gcc -E -undef -traditional -x assembler-with-cpp -o - -
#define derivePrim(ty, ctr, sz, align) \
instance Prim ty where {                                        \
  sizeOf# _ = unI# sz                                           \
; alignment# _ = unI# align   

derivePrim(Word, W#, sIZEOF_WORD, aLIGNMENT_WORD)
# 1 "<stdin>"
# 1 "<command-line>"
# 1 "<stdin>"





instance Prim Word where {                                          sizeOf# _ =
unI#  sIZEOF_WORD                                           ; alignment# _ =
unI#  aLIGNMENT_WORD

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

Clang:

--------------------------------------------------------
$ clang -E -undef -traditional -x assembler-with-cpp -o - -
#define derivePrim(ty, ctr, sz, align) \
instance Prim ty where {                                        \
  sizeOf# _ = unI# sz                                           \
; alignment# _ = unI# align   

derivePrim(Word, W#, sIZEOF_WORD, aLIGNMENT_WORD)
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<stdin>" 2





instance Prim Word where { sizeOf# _ = unI" sIZEOF_WORD" ; alignment# _ = unI"
aLIGNMENT_WORD"
--------------------------------------------------------

If it's not outrageous, could this be accommodated at all?

Attached is a file containing the problematic parts (it is a smaller version of
the attachment from bug 16363.) You can run 'gcc -E -x assembler-with-cpp' over
it to see the expected output vs what Clang outputs.

-- 
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/20130619/71d272af/attachment.html>


More information about the llvm-bugs mailing list