Commit Graph

53 Commits

Author SHA1 Message Date
Christudasan Devadasan 8c5e6fa657 Updated the signature for some stack related intrinsics (CLANG)
Modified the intrinsics
int_addressofreturnaddress,
int_frameaddress & int_sponentry.
This commit depends on the changes in rL366679

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D64563

llvm-svn: 366683
2019-07-22 12:50:30 +00:00
Eli Friedman c4c43b2bad [EH] Rename llvm.x86.seh.recoverfp intrinsic to llvm.eh.recoverfp
This is the clang counterpart to D56747.

Patch by Mandeep Singh Grang.

Differential Revision: https://reviews.llvm.org/D56748

llvm-svn: 351284
2019-01-16 00:50:44 +00:00
Mandeep Singh Grang 1f6fb8d063 [COFF, ARM64] Enable SEH for ARM64 Windows
Reviewers: rnk, mstorsjo, ssijaric, haripul, TomTan

Reviewed By: rnk

Subscribers: kristof.beyls, chrib, cfe-commits

Differential Revision: https://reviews.llvm.org/D50029

llvm-svn: 338405
2018-07-31 17:42:05 +00:00
Reid Kleckner fb93154bf1 [MS] Don't escape MS C++ names with \01
It is not needed after LLVM r327734. Now it will be easier to copy-paste
IR symbol names from Clang.

llvm-svn: 327738
2018-03-16 20:36:49 +00:00
Rafael Espindola 922f2aa9b2 Bring r325915 back.
The tests that failed on a windows host have been fixed.

Original message:

Start setting dso_local for COFF.

With this there are still some GVs where we don't set dso_local
because setGVProperties is never called. I intend to fix that in
followup commits. This is just the bare minimum to teach
shouldAssumeDSOLocal what it should do for COFF.

llvm-svn: 325940
2018-02-23 19:30:48 +00:00
Rafael Espindola 43ce3a3a4d Revert "Start setting dso_local for COFF."
This reverts commit r325915.

It will take some time to fix the failures on a windows host.

llvm-svn: 325929
2018-02-23 18:09:29 +00:00
Rafael Espindola 004d240b6a Start setting dso_local for COFF.
With this there are still some GVs where we don't set dso_local
because setGVProperties is never called. I intend to fix that in
followup commits. This is just the bare minimum to teach
shouldAssumeDSOLocal what it should do for COFF.

llvm-svn: 325915
2018-02-23 15:32:32 +00:00
David Majnemer 4ff6f7362b Remove -fnew-ms-eh
This flag no longer controls any behavior inside of clang.

llvm-svn: 261423
2016-02-20 09:23:41 +00:00
Reid Kleckner 39329d57b5 Reland "[SEH] Use llvm.x86.seh.recoverfp for SEH filters on x64 as well as 32bit"
I forgot to initialize RecoverFP.

llvm-svn: 255731
2015-12-16 00:26:37 +00:00
Reid Kleckner d8f719fa1c Revert "[SEH] Use llvm.x86.seh.recoverfp for SEH filters on x64 as well as 32bit"
This reverts commit r255710.

llvm-svn: 255728
2015-12-16 00:20:21 +00:00
Reid Kleckner cf2626600c [SEH] Use llvm.x86.seh.recoverfp for SEH filters on x64 as well as 32bit
llvm-svn: 255710
2015-12-15 23:47:40 +00:00
David Majnemer 4e52d6f811 Update clang to use the updated LLVM EH instructions
Depends on D15139.

Reviewers: rnk

Differential Revision: http://reviews.llvm.org/D15140

llvm-svn: 255423
2015-12-12 05:39:21 +00:00
Reid Kleckner 129552b375 [WinEH] Remove NewMSEH and enable its behavior by default
Testing has shown that it is at least as reliable as the old landingpad
pattern matching code.

llvm-svn: 249647
2015-10-08 01:13:52 +00:00
Reid Kleckner bb34b60359 [SEH] Use catchret in the new EH IR like we do for C++
Also add tests for SEH with the new IRGen.

llvm-svn: 247318
2015-09-10 18:39:41 +00:00
John McCall 0a49015629 Collect SEH captures in a set instead of a vector to avoid
doing redundant work if a variable is used multiple times.

Fixes PR24751.

llvm-svn: 247075
2015-09-08 21:15:22 +00:00
Reid Kleckner 8819a4065f Re-enable 32-bit SEH after the alignment fix
llvm-svn: 241878
2015-07-10 00:16:25 +00:00
Reid Kleckner e7844ea7f8 Disable 32-bit SEH, again
Move the diagnostic back to codegen so that we can compile ATL on the
self-host bot. We don't actually end up emitting code for the __try, so
the diagnostic won't be hit.

llvm-svn: 241761
2015-07-08 23:57:03 +00:00
Reid Kleckner 338635389f [SEH] Re-enable SEH on x86 Windows after r241699
llvm-svn: 241704
2015-07-08 18:27:10 +00:00
Reid Kleckner 15d152d3ac [SEH] Switch from frameaddress(0) to localaddress
This should do the right thing for stack realignment prologues.

llvm-svn: 241644
2015-07-07 23:23:31 +00:00
Reid Kleckner 98cb8ba64c Update clang for intrinsic rename of framerecover to localrecover
llvm-svn: 241634
2015-07-07 22:26:07 +00:00
Reid Kleckner 9fe7f2396b Revert "Revert 241171, 241187, 241199 (32-bit SEH)."
This reverts commit r241244, but restricts SEH support to Win64.

This way, Chromium builds will still fall back on TUs with SEH, and
Clang developers can work on this incrementally upstream while patching
this small predicate locally. It'll also make it easier to review small
fixes.

llvm-svn: 241533
2015-07-07 00:36:30 +00:00
Nico Weber e4f974c6fb Revert 241171, 241187, 241199 (32-bit SEH).
It still doesn't produce quite the right code, test binaries built with this
enabled fail some tests.

llvm-svn: 241244
2015-07-02 06:10:53 +00:00
Reid Kleckner 698310b004 [SEH] Update EmitCapturedLocals to match r241187
It was still using frameaddress(1) to get the parent FP, even though it
had the value it wanted as a parameter.

llvm-svn: 241199
2015-07-01 22:33:45 +00:00
Reid Kleckner eb11c41900 [SEH] Delete the 32-bit IR lowering for __finally blocks and use x64
32-bit finally funclets are intended to be called both directly from the
parent function and indirectly from the EH runtime. Because we aren't
contorting LLVM's X86 prologue to match MSVC's, calling the finally
block directly passes in a different value of EBP than the one that the
runtime provides. We need an adapter thunk to adjust EBP to the expected
value. However, WinEHPrepare already has to solve this problem when
cleanups are not pre-outlined, so we can go ahead and rely on it rather
than duplicating work.

Now we only do the llvm.x86.seh.recoverfp dance for 32-bit SEH filter
functions.

llvm-svn: 241187
2015-07-01 21:00:00 +00:00
Reid Kleckner d0d9a1f63f [SEH] Add 32-bit lowering for SEH __try
This re-lands r236052 and adds support for __exception_code().

In 32-bit SEH, the exception code is not available in eax. It is only
available in the filter function, and now we arrange to load it and
store it into an escaped variable in the parent frame.

As a consequence, we have to disable the "catch i8* null" optimization
on 32-bit and always generate a filter function. We can re-enable the
optimization if we detect an __except block that doesn't use the
exception code, but this probably isn't worth optimizing.

Reviewers: majnemer

Differential Revision: http://reviews.llvm.org/D10852

llvm-svn: 241171
2015-07-01 17:10:10 +00:00
David Majnemer fcbdb6ea58 Update clang to take into account the changes to personality fns
llvm-svn: 239941
2015-06-17 20:53:19 +00:00
Reid Kleckner 0b9bbbfc13 Revert "Re-land r236052, "[SEH] Add 32-bit lowering code for __try""
This reverts commit r239415. This was committed accidentally, LLVM isn't
ready for this.

llvm-svn: 239417
2015-06-09 17:49:42 +00:00
Reid Kleckner 65870442b3 Re-land r236052, "[SEH] Add 32-bit lowering code for __try"
This reverts r236167.

LLVM should be ready for this now.

llvm-svn: 239415
2015-06-09 17:47:50 +00:00
Reid Kleckner cb7a0a0562 Revert most of r236271, leaving only the datalayout change in lib/Basic/Targets.cpp
llvm-svn: 236274
2015-04-30 22:29:25 +00:00
Reid Kleckner af67602e14 Use 4 byte preferred aggregate alignment in datalayout on x86 Win32
llvm-svn: 236271
2015-04-30 22:13:05 +00:00
Reid Kleckner be9843ce54 Revert r236128, LLVM isn't falling back in the right way
llvm-svn: 236167
2015-04-29 21:55:21 +00:00
Reid Kleckner 0bb12a8981 Re-land r236052, the linker errors were fixed by LLVM r236123
Basic __finally blocks don't cause linker errors anymore (although they
are miscompiled).

llvm-svn: 236128
2015-04-29 17:17:17 +00:00
Nico Weber ea721b64df Revert r236052, it caused linker errors when building 32-bit applications.
llvm-svn: 236082
2015-04-29 03:08:32 +00:00
Reid Kleckner ddd40964f0 [SEH] Add 32-bit lowering code for __try
This is just the clang-side of 32-bit SEH. LLVM still needs work, and it
will determinstically fail to compile until it's feature complete.

On x86, all outlined handlers have no parameters, but they do implicitly
take the EBP value passed in and use it to address locals of the parent
frame. We model this with llvm.frameaddress(1).

This works (mostly), but __finally block inlining can break it. For now,
we apply the 'noinline' attribute. If we really want to inline __finally
blocks on 32-bit x86, we should teach the inliner how to untangle
frameescape and framerecover.

Promote the error diagnostic from codegen to sema. It now rejects SEH on
non-Windows platforms. LLVM doesn't implement SEH on non-x86 Windows
platforms, but there's nothing preventing it.

llvm-svn: 236052
2015-04-28 22:19:32 +00:00
Reid Kleckner e0bca755d8 Remove stale FIXMEs from test case
llvm-svn: 235937
2015-04-27 23:14:24 +00:00
David Majnemer 2ccba83401 [MS ABI] Use the right types for filter and finally blocks
The type for abnormal_termination can't be an i1, it an i8.
Filter functions return 'LONG', not 'int'.

llvm-svn: 235161
2015-04-17 06:57:25 +00:00
Reid Kleckner ebaf28d13d Reland r234613 (and follow-ups 234614, 234616, 234618)
The frameescape intrinsic cannot be inlined, so I fixed the inliner in
r234937. This should address PR23216.

llvm-svn: 234942
2015-04-14 20:59:00 +00:00
Nico Weber ad108337cf Revert r234613 (and follow-ups 234614, 234616, 234618), it caused PR23216.
llvm-svn: 234789
2015-04-13 20:04:22 +00:00
Nico Weber f2a39a7b4e Revert r234786, it contained a bunch of stuff I did not mean to commit.
llvm-svn: 234787
2015-04-13 20:03:03 +00:00
Nico Weber b31abb05fb Revert r234613 (and follow-ups 234614, 234616, 234618), it caused PR23216.
llvm-svn: 234786
2015-04-13 20:01:20 +00:00
Reid Kleckner 11859afd5f [SEH] Re-land r234532, but use internal linkage for all SEH helpers
Even though these symbols are in a comdat group, the Microsoft linker
really wants them to have internal linkage.

I'm planning to tweak the mangling in a follow-up change. This is a
straight revert with a 1-line fix.

llvm-svn: 234613
2015-04-10 17:34:52 +00:00
Nico Weber bd51a6a99f Revert r234532 for a bit, it very likely caused http://crbug.com/475768
llvm-svn: 234563
2015-04-10 04:33:03 +00:00
Reid Kleckner 0dbecf2b78 [SEH] Outline finally blocks using the new variable capture support
WinEHPrepare was going to have to pattern match the control flow merge
and split that the old lowering used, and that wasn't really feasible.

Now we can teach WinEHPrepare to pattern match this, which is much
simpler:
  %fp = call i8* @llvm.frameaddress(i32 0)
  call void @func(iN [01], i8* %fp)

This prototype happens to match the prototype used by the Win64 SEH
personality function, so this is really simple.

llvm-svn: 234532
2015-04-09 20:37:24 +00:00
David Blaikie a953f2825b Update Clang tests to handle explicitly typed load changes in LLVM.
llvm-svn: 230795
2015-02-27 21:19:58 +00:00
Reid Kleckner a593000f01 Add the 'noinline' attribute to call sites within __try bodies
LLVM doesn't support non-call exceptions, so inlining makes it harder to
catch such asynchronous exceptions.

llvm-svn: 228876
2015-02-11 21:40:48 +00:00
Reid Kleckner deeddeced3 Re-land r228258 and make clang-cl's /EHs- disable -fexceptions again
After r228258, Clang started emitting C++ EH IR that LLVM wasn't ready
to deal with, even when exceptions were disabled with /EHs-. This time,
make /EHs- turn off -fexceptions while still emitting exceptional
constructs in functions using __try.  Since Sema rejects C++ exception
handling constructs before CodeGen, landingpads should only appear in
such functions as the result of a __try.

llvm-svn: 228329
2015-02-05 18:56:03 +00:00
Reid Kleckner aca01db706 Implement IRGen for SEH __finally and AbnormalTermination
Previously we would simply double-emit the body of the __finally block,
but that doesn't work when it contains any kind of Decl, which we can't
double emit.

This fixes that by emitting the block once and branching into a shared
code region and then branching back out.

llvm-svn: 228222
2015-02-04 22:37:07 +00:00
Reid Kleckner 3a417c301b SEH: Don't jump to an unreachable continuation block
If both the __try and __except blocks do not return, we want to delete
the continuation block as unreachable instead.

llvm-svn: 227627
2015-01-30 22:16:45 +00:00
Reid Kleckner 2a2e156318 SEH: Emit the constant filter 1 as a catch-all
Minor optimization of code like __try { ... } __except(1) { ... }.

llvm-svn: 226766
2015-01-22 02:25:56 +00:00
Reid Kleckner 1d59f99f5c Initial support for Win64 SEH IR emission
The lowering looks a lot like normal EH lowering, with the exception
that the exceptions are caught by executing filter expression code
instead of matching typeinfo globals. The filter expressions are
outlined into functions which are used in landingpad clauses where
typeinfo would normally go.

Major aspects that still need work:
- Non-call exceptions in __try bodies won't work yet. The plan is to
  outline the __try block in the frontend to keep things simple.
- Filter expressions cannot use local variables until capturing is
  implemented.
- __finally blocks will not run after exceptions. Fixing this requires
  work in the LLVM SEH preparation pass.

The IR lowering looks like this:

// C code:
bool safe_div(int n, int d, int *r) {
  __try {
    *r = normal_div(n, d);
  } __except(_exception_code() == EXCEPTION_INT_DIVIDE_BY_ZERO) {
    return false;
  }
  return true;
}

; LLVM IR:
define i32 @filter(i8* %e, i8* %fp) {
  %ehptrs = bitcast i8* %e to i32**
  %ehrec = load i32** %ehptrs
  %code = load i32* %ehrec
  %matches = icmp eq i32 %code, i32 u0xC0000094
  %matches.i32 = zext i1 %matches to i32
  ret i32 %matches.i32
}

define i1 zeroext @safe_div(i32 %n, i32 %d, i32* %r) {
  %rr = invoke i32 @normal_div(i32 %n, i32 %d)
      to label %normal unwind to label %lpad

normal:
  store i32 %rr, i32* %r
  ret i1 1

lpad:
  %ehvals = landingpad {i8*, i32} personality i32 (...)* @__C_specific_handler
      catch i8* bitcast (i32 (i8*, i8*)* @filter to i8*)
  %ehptr = extractvalue {i8*, i32} %ehvals, i32 0
  %sel = extractvalue {i8*, i32} %ehvals, i32 1
  %filter_sel = call i32 @llvm.eh.seh.typeid.for(i8* bitcast (i32 (i8*, i8*)* @filter to i8*))
  %matches = icmp eq i32 %sel, %filter_sel
  br i1 %matches, label %eh.except, label %eh.resume

eh.except:
  ret i1 false

eh.resume:
  resume
}

Reviewers: rjmccall, rsmith, majnemer

Differential Revision: http://reviews.llvm.org/D5607

llvm-svn: 226760
2015-01-22 01:36:17 +00:00