Skip to content

Commit

Permalink
Fix Issue 21159 - DWARF: DW_AT_pure should be emitted for pure functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Luhrel authored and dlang-bot committed Aug 26, 2020
1 parent c6bb558 commit 4028c58
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/dmd/backend/dwarfdbginf.d
Original file line number Diff line number Diff line change
Expand Up @@ -1646,6 +1646,15 @@ static if (ELFOBJ || MACHOBJ)
{
abuf.writeByte(DW_AT_external); abuf.writeByte(DW_FORM_flag);
}
if (sfunc.Sfunc.Fflags3 & Fpure)
{
abuf.writeByte(DW_AT_pure);
static if (DWARF_VERSION >= 4)
abuf.writeByte(DW_FORM_flag_present);
else
abuf.writeByte(DW_FORM_flag);
}

abuf.writeByte(DW_AT_low_pc); abuf.writeByte(DW_FORM_addr);
abuf.writeByte(DW_AT_high_pc); abuf.writeByte(DW_FORM_addr);
abuf.writeByte(DW_AT_frame_base); abuf.writeByte(DW_FORM_data4);
Expand Down Expand Up @@ -1676,6 +1685,12 @@ static if (ELFOBJ || MACHOBJ)
if (sfunc.Sclass == SCglobal)
debug_info.buf.writeByte(1); // DW_AT_external

static if (DWARF_VERSION < 4)
{
if (sfunc.Sfunc.Fflags3 & Fpure)
debug_info.buf.writeByte(true); // DW_AT_pure
}

// DW_AT_low_pc and DW_AT_high_pc
dwarf_appreladdr(debug_info.seg, debug_info.buf, seg, funcoffset);
dwarf_appreladdr(debug_info.seg, debug_info.buf, seg, funcoffset + sfunc.Ssize);
Expand Down
18 changes: 15 additions & 3 deletions test/dshell/dwarf.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import std.algorithm;
import std.file;
import std.process;

import std.conv;

int main()
{
version(DigitalMars) { }
Expand All @@ -24,11 +26,21 @@ int main()
else
immutable slash = "/";


// If the Unix system doesn't have objdump, disable the tests
auto sysHasObjdump = executeShell("objdump --help");
if (sysHasObjdump.status)
auto sysObjdump = executeShell("objdump --version");
if (sysObjdump.status)
return DISABLED;
// DWARF 3 (and 4) support has been implemented in version 2.20 (2.20.51.0.1)
try
{
if(sysObjdump.output.split("\n")[0][$ - 4 .. $].to!double < 2.20)
return DISABLED;
}
catch (ConvException ce)
{
// The conversion failed, then it's definitively an old version (or a too new)
return DISABLED;
}

immutable extra_dwarf_dir = EXTRA_FILES ~ slash ~ "dwarf" ~ slash;
bool failed;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DW_AT_pure
9 changes: 9 additions & 0 deletions test/dshell/extra-files/dwarf/fix21159.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
void main()
{

}

void foo() pure
{

}

0 comments on commit 4028c58

Please sign in to comment.