Skip to content

Commit

Permalink
-betterC: Don't use unsupported EH for handling clean-ups
Browse files Browse the repository at this point in the history
A reboot of ldc-developers#3480, fixing ldc-developers#3479 and related issues.
  • Loading branch information
kinke committed Jun 28, 2020
1 parent a31ac78 commit 9444453
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gen/funcgenstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ llvm::CallSite FuncGenState::callOrInvoke(llvm::Value *callee,

// Intrinsics don't support invoking and 'nounwind' functions don't need it.
const bool doesNotThrow =
isNothrow ||
isNothrow || global.params.betterC ||
(calleeFn && (calleeFn->isIntrinsic() || calleeFn->doesNotThrow()));

// calls inside a funclet must be annotated with its value
Expand Down
36 changes: 36 additions & 0 deletions tests/linking/betterc_cleanups.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// RUN: %ldc -betterC -run %s > %t.stdout
// RUN: FileCheck %s < %t.stdout

import core.stdc.stdio;

void notNothrow() { printf("notNothrow\n"); }

struct WithDtor
{
~this() { printf("destructing\n"); }
}

void foo(WithDtor a, bool skip)
{
if (skip)
return;

notNothrow();
}

extern(C) int main()
{
WithDtor a;
scope(exit) printf("exiting\n");

foo(a, true);
// CHECK: destructing

foo(a, false);
// CHECK-NEXT: notNothrow
// CHECK-NEXT: destructing

return 0;
// CHECK-NEXT: exiting
// CHECK-NEXT: destructing
}

0 comments on commit 9444453

Please sign in to comment.