Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions .github/actions/4c-test-dmd/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,7 @@ runs:
- name: 'Posix: Run DMD testsuite'
if: runner.os != 'Windows'
shell: bash
run: |
set -eux
repoDir=$PWD
cd ../build
if type -P apk &>/dev/null; then
# Alpine: run full dmd-testsuite-debug
ctest -V -R 'dmd-testsuite' -E '^dmd-testsuite$'
# these two tests require extra flags "-link-defaultlib-debug -frame-pointer=all": https://github.com/ldc-developers/ldc/issues/4694
# => remove before running optimized dmd-testsuite separately
rm $repoDir/tests/dmd/runnable/{test17559.d,test19086.d}
ctest -V -R '^dmd-testsuite$'
else
ctest -V -R "dmd-testsuite"
fi
run: cd ../build && ctest -V -R "dmd-testsuite"

- name: 'Windows: Run DMD testsuite'
if: runner.os == 'Windows'
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# LDC master

#### Big news
- Keep frame pointers by default with `-O` for some targets, notably AArch64 (except Windows), x86_64 (except Windows and glibc Linux), Windows x86, and Android. This fixes druntime backtraces with optimized code (incl. prebuilt druntime/Phobos). (#4889)
- ldc2.conf: Arrays can now be appended to via the `~=` operator. (#4848, #4856)

#### Platform support
Expand Down
36 changes: 28 additions & 8 deletions gen/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,6 @@ void applyTargetMachineAttributes(llvm::Function &func,
opts::setFunctionAttributes(cpu, features, func);
if (opts::fFastMath) // -ffast-math[=true] overrides -enable-unsafe-fp-math
func.addFnAttr("unsafe-fp-math", "true");
if (!func.hasFnAttribute("frame-pointer")) // not explicitly set by user
func.addFnAttr("frame-pointer", isOptimizationEnabled() ? "none" : "all");
}

void applyXRayAttributes(FuncDeclaration &fdecl, llvm::Function &func) {
Expand All @@ -448,6 +446,23 @@ void applyXRayAttributes(FuncDeclaration &fdecl, llvm::Function &func) {
}
}

// Keep frame pointers by default with enabled optimizations?
// The logic is very loosely based on clang's
// `useFramePointerForTargetByDefault()`, as well as backtrace test results for
// druntime-test-exceptions-release.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bool keepFramePointersByDefault() {
const auto &triple = *global.params.targetTriple;
if (triple.isAndroid())
return true;
if (triple.isAArch64())
return !triple.isOSWindows();
if (triple.getArch() == llvm::Triple::x86)
return triple.isOSWindows(); // required for druntime backtraces
if (triple.getArch() == llvm::Triple::x86_64)
return !(triple.isOSWindows() || triple.isGNUEnvironment());
return false;
}

void onlyOneMainCheck(FuncDeclaration *fd) {
if (!fd->fbody) // multiple *declarations* are fine
return;
Expand Down Expand Up @@ -1174,6 +1189,17 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) {
func->addFnAttr("use-sample-profile");
}

if (fd->hasInlineAsm()) {
// disable frame-pointer-elimination for functions with DMD-style inline asm
func->addFnAttr("frame-pointer", "all");
} else if (!func->hasFnAttribute("frame-pointer")) {
// not explicitly set by user
func->addFnAttr("frame-pointer",
isOptimizationEnabled() && !keepFramePointersByDefault()
? "none"
: "all");
}

llvm::BasicBlock *beginbb =
llvm::BasicBlock::Create(gIR->context(), "", func);

Expand Down Expand Up @@ -1210,12 +1236,6 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) {
emitDMDStyleFunctionTrace(*gIR, fd, funcGen);
}

// disable frame-pointer-elimination for functions with DMD-style inline asm
if (fd->hasInlineAsm()) {
func->addFnAttr(
llvm::Attribute::get(gIR->context(), "frame-pointer", "all"));
}

// give the 'this' parameter (an lvalue) storage and debug info
if (irFty.arg_this) {
LLValue *thisvar = irFunc->thisArg;
Expand Down
4 changes: 0 additions & 4 deletions tests/codegen/attr_targetoptions.d
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// Tests that our TargetMachine options are added as function attributes

// RUN: %ldc -c -output-ll -of=%t.ll %s
// RUN: FileCheck %s --check-prefix=COMMON --check-prefix=WITH_FP < %t.ll
// RUN: %ldc -c -output-ll -of=%t.ll %s -O2
// RUN: FileCheck %s --check-prefix=COMMON --check-prefix=NO_FP < %t.ll
// RUN: %ldc -c -output-ll -of=%t.ll %s -O2 -frame-pointer=all
// RUN: FileCheck %s --check-prefix=COMMON --check-prefix=WITH_FP < %t.ll
// RUN: %ldc -c -output-ll -of=%t.ll %s -frame-pointer=none -mattr=test
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/exception_stack_trace.d
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %ldc -g -frame-pointer=all -link-defaultlib-debug %s -of=%t%exe
// RUN: %ldc -g %s -of=%t%exe
// RUN: %t%exe | FileCheck %s

void bar()
Expand Down
8 changes: 4 additions & 4 deletions tests/codegen/frame_pointer_x86.d
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// REQUIRES: target_X86

// RUN: %ldc -c -mtriple=x86_64 -output-s -of=%t.s %s
// RUN: %ldc -c -mtriple=x86_64-linux-gnu -output-s -of=%t.s %s
// RUN: FileCheck %s --check-prefixes=COMMON,FP < %t.s
// RUN: %ldc -c -mtriple=x86_64 -output-s -of=%t.s %s -O2
// RUN: %ldc -c -mtriple=x86_64-linux-gnu -output-s -of=%t.s %s -O2
// RUN: FileCheck %s --check-prefixes=COMMON,NO_FP < %t.s
// RUN: %ldc -c -mtriple=x86_64 -output-s -of=%t.s %s -O2 -frame-pointer=all
// RUN: %ldc -c -mtriple=x86_64-linux-gnu -output-s -of=%t.s %s -O2 -frame-pointer=all
// RUN: FileCheck %s --check-prefixes=COMMON,FP < %t.s
// RUN: %ldc -c -mtriple=x86_64 -output-s -of=%t.s %s -frame-pointer=none
// RUN: %ldc -c -mtriple=x86_64-linux-gnu -output-s -of=%t.s %s -frame-pointer=none
// RUN: FileCheck %s --check-prefixes=COMMON,NO_FP < %t.s

// COMMON-LABEL: _D17frame_pointer_x8613inlineAsmLeafFZv:
Expand Down
4 changes: 2 additions & 2 deletions tests/codegen/vector_abi_x86.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

// REQUIRES: host_X86

// RUN: %ldc -O -output-s -m32 -of=%t_32.s %s -mattr=+sse2
// RUN: %ldc -O -frame-pointer=none -output-s -m32 -of=%t_32.s %s -mattr=+sse2
// RUN: FileCheck --check-prefix=COMMON %s < %t_32.s

// RUN: %ldc -O -output-s -m64 -of=%t_64.s %s
// RUN: %ldc -O -frame-pointer=none -output-s -m64 -of=%t_64.s %s
// RUN: FileCheck --check-prefix=COMMON --check-prefix=X64 %s < %t_64.s

import core.simd;
Expand Down
2 changes: 0 additions & 2 deletions tests/dmd/runnable/test17559.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// REQUIRED_ARGS: -g
// REQUIRED_ARGS(linux freebsd openbsd dragonflybsd): -L-export-dynamic
// LDC (required for Win32 and -O): REQUIRED_ARGS(windows32): -link-defaultlib-debug
// LDC (FreeBSD's libexecinfo apparently doesn't like elided frame pointers): REQUIRED_ARGS(freebsd): -link-defaultlib-debug -frame-pointer=all
// PERMUTE_ARGS:
// DISABLED: osx

Expand Down
1 change: 0 additions & 1 deletion tests/dmd/runnable/test19086.d
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// REQUIRED_ARGS: -g
// REQUIRED_ARGS(linux freebsd openbsd dragonflybsd): -L-export-dynamic
// LDC (FreeBSD's libexecinfo apparently doesn't like elided frame pointers): REQUIRED_ARGS(freebsd): -link-defaultlib-debug -frame-pointer=all
// DISABLED: LDC_win32 // no file/line info for the `run19086` frame (and only that frame), even without -O
// PERMUTE_ARGS:
// DISABLED: osx
Expand Down
3 changes: 1 addition & 2 deletions tests/sanitizers/fuzz_asan.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

// REQUIRES: Fuzzer, ASan

// See https://github.com/ldc-developers/ldc/issues/2222 for -frame-pointer=all
// See https://github.com/ldc-developers/ldc/pull/4328 for -fsanitize-address-use-after-return=never
// RUN: %ldc -g -fsanitize=address,fuzzer -fsanitize-address-use-after-return=never -frame-pointer=all %s -of=%t%exe
// RUN: %ldc -g -fsanitize=address,fuzzer -fsanitize-address-use-after-return=never %s -of=%t%exe
// RUN: not %t%exe 2>&1 | FileCheck %s

bool FuzzMe(ubyte* data, size_t dataSize)
Expand Down
Loading