www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17651] New: Segfult when parsing Ddoc ESCAPES macro

https://issues.dlang.org/show_bug.cgi?id=17651

          Issue ID: 17651
           Summary: Segfult when parsing Ddoc ESCAPES macro
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: doob me.com

The following example results in a segmentation fault. Looking at the stack
trace it looks like it the segmentation fault occurs when parsing the ESCAPES
Ddoc macro:

$ cat foo.d
/**
Macros:
ESCAPES = /a/b/
*/
void foo() {}

$ lldb -- dmd foo.d -c -D
(lldb) target create "dmd"
Current executable set to 'dmd' (x86_64).
(lldb) settings set -- target.run-args  "foo.d" "-c" "-D"
(lldb) r
Process 1511 launched: '~/.dvm/compilers/dmd-2.075.0-b4/osx/bin/dmd' (x86_64)
Process 1511 stopped
* thread #1: tid = 0x1106382, 0x000000010009e6e0
dmd`DocComment::parseEscapes(Escape**, char const*, unsigned long) + 40, queue
= 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x000000010009e6e0 dmd`DocComment::parseEscapes(Escape**, char
const*, unsigned long) + 40
dmd`DocComment::parseEscapes:
->  0x10009e6e0 <+40>: movq   (%rdi), %r12
    0x10009e6e3 <+43>: testq  %r12, %r12
    0x10009e6e6 <+46>: jne    0x10009e71c               ; <+100>
    0x10009e6e8 <+48>: movq   0x29db79(%rip), %rdi      ; (void
*)0x0000000100381898: D26TypeInfo_S4ddmd3doc6Escape6__initZ
(lldb) bt
* thread #1: tid = 0x1106382, 0x000000010009e6e0
dmd`DocComment::parseEscapes(Escape**, char const*, unsigned long) + 40, queue
= 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x000000010009e6e0 dmd`DocComment::parseEscapes(Escape**, char
const*, unsigned long) + 40
    frame #1: 0x000000010009e5af dmd`DocComment::parseMacros(Escape**, Macro**,
char const*, unsigned long) + 351
    frame #2: 0x000000010009698d dmd`MacroSection::write(Loc, DocComment*,
Scope*, Array<Dsymbol*>*, OutBuffer*) + 37
    frame #3: 0x000000010009f14c dmd`DocComment::writeSections(Scope*,
Array<Dsymbol*>*, OutBuffer*) + 1420
    frame #4: 0x000000010009a041 dmd`emitComment::EmitComment::emit(Scope*,
Dsymbol*, char const*) + 3121
    frame #5: 0x0000000100099395 dmd`emitComment(Dsymbol*, OutBuffer*, Scope*)
+ 93
    frame #6: 0x00000001000990e1 dmd`emitMemberComments(ScopeDsymbol*,
OutBuffer*, Scope*) + 1193
    frame #7: 0x0000000100097725 dmd`gendocfile(Module*) + 2981
    frame #8: 0x000000010015c32e dmd`D4ddmd4mars7tryMainFmPPxaZi + 22782
    frame #9: 0x0000000100001523 dmd`_Dmain + 39
    frame #10: 0x00000001002bf22c
dmd`D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFNlZv + 40
    frame #11: 0x00000001002bf154
dmd`D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ7tryExecMFNlMDFZvZv + 32
    frame #12: 0x00000001002bf1d1
dmd`D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFNlZv + 45
    frame #13: 0x00000001002bf154
dmd`D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ7tryExecMFNlMDFZvZv + 32
    frame #14: 0x00000001002bf0c7 dmd`_d_run_main + 459
    frame #15: 0x000000010000153c dmd`main + 16
    frame #16: 0x00000001000014f4 dmd`start + 52

The issue seems to occur on all versions of DMD. If I remove the ESCAPES macro
the segmentation fault does not occur.

--
Jul 14