Commit Graph

51 Commits

Author SHA1 Message Date
Mandeep Singh Grang ff3f88d77c [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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338405 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-31 17:42:05 +00:00
Reid Kleckner c45a02c8a8 [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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@327738 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-16 20:36:49 +00:00
Rafael Espindola 0e355701be 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@325940 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-23 19:30:48 +00:00
Rafael Espindola 5626325f6c Revert "Start setting dso_local for COFF."
This reverts commit r325915.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@325929 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-23 18:09:29 +00:00
Rafael Espindola db74826fe1 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@325915 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-23 15:32:32 +00:00
David Majnemer aed82c0255 Remove -fnew-ms-eh
This flag no longer controls any behavior inside of clang.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@261423 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-20 09:23:41 +00:00
Reid Kleckner 6d0f3306b8 Reland "[SEH] Use llvm.x86.seh.recoverfp for SEH filters on x64 as well as 32bit"
I forgot to initialize RecoverFP.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255731 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-16 00:26:37 +00:00
Reid Kleckner 2f485a10cd Revert "[SEH] Use llvm.x86.seh.recoverfp for SEH filters on x64 as well as 32bit"
This reverts commit r255710.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255728 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-16 00:20:21 +00:00
Reid Kleckner 09d48038e1 [SEH] Use llvm.x86.seh.recoverfp for SEH filters on x64 as well as 32bit
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255710 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-15 23:47:40 +00:00
David Majnemer 29849678b0 Update clang to use the updated LLVM EH instructions
Depends on D15139.

Reviewers: rnk

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255423 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-12 05:39:21 +00:00
Reid Kleckner af74df2b28 [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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249647 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-08 01:13:52 +00:00
Reid Kleckner c0e1672f1e [SEH] Use catchret in the new EH IR like we do for C++
Also add tests for SEH with the new IRGen.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@247318 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-10 18:39:41 +00:00
John McCall b6defdfa47 Collect SEH captures in a set instead of a vector to avoid
doing redundant work if a variable is used multiple times.

Fixes PR24751.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@247075 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-08 21:15:22 +00:00
Reid Kleckner 8b1bc0abb2 Re-enable 32-bit SEH after the alignment fix
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241878 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-10 00:16:25 +00:00
Reid Kleckner 0a79d0e495 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241761 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-08 23:57:03 +00:00
Reid Kleckner ebb999818e [SEH] Re-enable SEH on x86 Windows after r241699
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241704 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-08 18:27:10 +00:00
Reid Kleckner 309647a473 [SEH] Switch from frameaddress(0) to localaddress
This should do the right thing for stack realignment prologues.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241644 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-07 23:23:31 +00:00
Reid Kleckner 55c7cc771e Update clang for intrinsic rename of framerecover to localrecover
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241634 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-07 22:26:07 +00:00
Reid Kleckner a4bd538963 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241533 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-07 00:36:30 +00:00
Nico Weber 6c5a911bba 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.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241244 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-02 06:10:53 +00:00
Reid Kleckner 3cc214289f [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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241199 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-01 22:33:45 +00:00
Reid Kleckner 184ac2d8e0 [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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241187 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-01 21:00:00 +00:00
Reid Kleckner 0e2d47b82f [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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241171 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-01 17:10:10 +00:00
David Majnemer fa3804032d Update clang to take into account the changes to personality fns
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239941 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-17 20:53:19 +00:00
Reid Kleckner a81d8fe06e 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239417 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-09 17:49:42 +00:00
Reid Kleckner b2c611a18b Re-land r236052, "[SEH] Add 32-bit lowering code for __try"
This reverts r236167.

LLVM should be ready for this now.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239415 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-09 17:47:50 +00:00
Reid Kleckner 45d60479b5 Revert most of r236271, leaving only the datalayout change in lib/Basic/Targets.cpp
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236274 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-30 22:29:25 +00:00
Reid Kleckner e2aa55a551 Use 4 byte preferred aggregate alignment in datalayout on x86 Win32
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236271 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-30 22:13:05 +00:00
Reid Kleckner ad68d1bbcf Revert r236128, LLVM isn't falling back in the right way
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236167 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-29 21:55:21 +00:00
Reid Kleckner b7183ef952 Re-land r236052, the linker errors were fixed by LLVM r236123
Basic __finally blocks don't cause linker errors anymore (although they
are miscompiled).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236128 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-29 17:17:17 +00:00
Nico Weber 50d6060ac8 Revert r236052, it caused linker errors when building 32-bit applications.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236082 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-29 03:08:32 +00:00
Reid Kleckner 24fca8241f [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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236052 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-28 22:19:32 +00:00
Reid Kleckner 41f0e7dde4 Remove stale FIXMEs from test case
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235937 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-27 23:14:24 +00:00
David Majnemer e1907cb197 [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'.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235161 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-17 06:57:25 +00:00
Reid Kleckner eec5f41a53 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@234942 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-14 20:59:00 +00:00
Nico Weber 804f40bf60 Revert r234613 (and follow-ups 234614, 234616, 234618), it caused PR23216.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@234789 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-13 20:04:22 +00:00
Nico Weber a5b191aa79 Revert r234786, it contained a bunch of stuff I did not mean to commit.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@234787 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-13 20:03:03 +00:00
Nico Weber 5aaa165ebe Revert r234613 (and follow-ups 234614, 234616, 234618), it caused PR23216.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@234786 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-13 20:01:20 +00:00
Reid Kleckner 48d7c1dcf4 [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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@234613 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-10 17:34:52 +00:00
Nico Weber 5e087128f8 Revert r234532 for a bit, it very likely caused http://crbug.com/475768
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@234563 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-10 04:33:03 +00:00
Reid Kleckner 1a48caef66 [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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@234532 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-09 20:37:24 +00:00
David Blaikie 1d7abba8db Update Clang tests to handle explicitly typed load changes in LLVM.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@230795 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-27 21:19:58 +00:00
Reid Kleckner ffb8cef8cf 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@228876 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-11 21:40:48 +00:00
Reid Kleckner 86837b8582 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@228329 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-05 18:56:03 +00:00
Reid Kleckner 7de7ebca0f 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@228222 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-04 22:37:07 +00:00
Reid Kleckner bc127a5c68 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@227627 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-30 22:16:45 +00:00
Reid Kleckner 37497377a8 SEH: Emit the constant filter 1 as a catch-all
Minor optimization of code like __try { ... } __except(1) { ... }.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@226766 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-22 02:25:56 +00:00
Reid Kleckner 4702b3a507 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@226760 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-22 01:36:17 +00:00
Nico Weber 2a5e840d9f Add an AST node for __leave statements, hook it up.
Codegen is still missing (and I won't work on that), but __leave is now
as implemented as __try and friends.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212425 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-07 00:12:30 +00:00
Benjamin Kramer 38d04e3098 test case hygiene.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199017 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-11 21:22:35 +00:00