aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGException.cpp
AgeCommit message (Collapse)AuthorFilesLines
2015-05-11Give isCompatibleWithMSVC a better interfaceDavid Majnemer1-1/+1
We now use an enum which maps the marketing name (almost always a year) to the major version number. llvm-svn: 236967
2015-05-10[MS ABI] Update EH emission for MSVC 2015 compatibilityDavid Majnemer1-1/+4
MSVC 2015 renamed the symbol found by name lookup for 'std::terminate' so we cannot rely on using '?terminate@@YAXXZ'. Furthermore, it seems that 2015 will be the first release of MSVC which permits inlining a function which is noexcept into a function which isn't. This is implemented by creating a cleanup for the invoker which jumps to __std_terminate. Clang's implementation of this aspect of the MSVC scheme is slightly less efficient in this respect because we use a catch handler configured as a catch-all handler instead. llvm-svn: 236961
2015-04-30Revert most of r236271, leaving only the datalayout change in ↵Reid Kleckner1-150/+84
lib/Basic/Targets.cpp llvm-svn: 236274
2015-04-30Use 4 byte preferred aggregate alignment in datalayout on x86 Win32Reid Kleckner1-84/+150
llvm-svn: 236271
2015-04-29Revert r236128, LLVM isn't falling back in the right wayReid Kleckner1-150/+84
llvm-svn: 236167
2015-04-29Re-land r236052, the linker errors were fixed by LLVM r236123Reid Kleckner1-84/+150
Basic __finally blocks don't cause linker errors anymore (although they are miscompiled). llvm-svn: 236128
2015-04-29Revert r236052, it caused linker errors when building 32-bit applications.Nico Weber1-150/+84
llvm-svn: 236082
2015-04-28[SEH] Add 32-bit lowering code for __tryReid Kleckner1-84/+150
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-23InstrProf: Stop using RegionCounter outside of CodeGenPGO (NFC)Justin Bogner1-4/+2
The RegionCounter type does a lot of legwork, but most of it is only meaningful within the implementation of CodeGenPGO. The uses elsewhere in CodeGen generally just want to increment or read counters, so do that directly. llvm-svn: 235664
2015-04-17[MS ABI] Use the right types for filter and finally blocksDavid Majnemer1-4/+6
The type for abnormal_termination can't be an i1, it an i8. Filter functions return 'LONG', not 'int'. llvm-svn: 235161
2015-04-14Reland r234613 (and follow-ups 234614, 234616, 234618)Reid Kleckner1-117/+148
The frameescape intrinsic cannot be inlined, so I fixed the inliner in r234937. This should address PR23216. llvm-svn: 234942
2015-04-13Revert r234613 (and follow-ups 234614, 234616, 234618), it caused PR23216.Nico Weber1-148/+117
llvm-svn: 234789
2015-04-13Revert r234786, it contained a bunch of stuff I did not mean to commit.Nico Weber1-117/+148
llvm-svn: 234787
2015-04-13Revert r234613 (and follow-ups 234614, 234616, 234618), it caused PR23216.Nico Weber1-148/+117
llvm-svn: 234786
2015-04-10[SEH] Re-land r234532, but use internal linkage for all SEH helpersReid Kleckner1-117/+148
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-10Revert r234532 for a bit, it very likely caused http://crbug.com/475768Nico Weber1-146/+115
llvm-svn: 234563
2015-04-09[SEH] Outline finally blocks using the new variable capture supportReid Kleckner1-115/+146
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-08Reland "[SEH] Implement filter capturing in CodeGen"Reid Kleckner1-20/+109
The test should be fixed. It was failing in NDEBUG builds due to a missing '*' character in a regex. In asserts builds, the pattern matched a single digit value, which became a double digit value in NDEBUG builds. Go figure. This reverts commit r234261. llvm-svn: 234447
2015-04-07Revert "[SEH] Implement filter capturing in CodeGen"Daniel Jasper1-109/+20
Test fails: http://lab.llvm.org:8080/green/job/clang-stage2-configure-Rlto_check/3182/ llvm-svn: 234306
2015-04-06[SEH] Implement filter capturing in CodeGenReid Kleckner1-20/+109
While capturing filters aren't very common, we'd like to outline __finally blocks in the frontend to simplify -O0 EH preparation and reduce code size. Finally blocks are usually have captures, and this is the first step towards that. Currently we don't support capturing 'this' or VLAs. Reviewers: majnemer Differential Revision: http://reviews.llvm.org/D8825 llvm-svn: 234261
2015-04-05[opaque pointer type] More GEP API migrationsDavid Blaikie1-1/+1
Looks like the VTable code in particular will need some work to pass around the pointee type explicitly. llvm-svn: 234128
2015-04-01[MS ABI] Disregard restrictive exception specificationsDavid Majnemer1-0/+8
MSVC treats all non-empty exception specifications the same way: all exceptions are permitted. The .xdata tables provide a way to efficiently lower exception specifications *but* this probably has to be implemented as a catch-all/rethrow mechanism instead of the Itanium way. This fixes PR23092. llvm-svn: 233787
2015-03-29[MS ABI] Rework .xdata HandlerType emissionDavid Majnemer1-1/+1
Utilizing IMAGEREL relocations for synthetic IR constructs isn't valuable, just clutter. While we are here, simplify HandlerType names by making the numeric value for the 'adjective' part of the mangled name instead of appending '.const', etc. The old scheme made for very long global names and leads to wordy things like '.std_bad_alloc' llvm-svn: 233503
2015-03-17MS ABI: Emit HandlerMap entries for C++ catchDavid Majnemer1-1/+2
The HandlerMap describes, to the runtime, what sort of catches surround the try. In principle, this structure has to be emitted by the backend because only it knows the layout of the stack (the runtime needs to know where on the stack the destination of a copy lives, etc.) but there is some C++ specific information that the backend can't reason about. Stick this information in special LLVM globals with the relevant "const", "volatile", "reference" info mangled into the name. llvm-svn: 232538
2015-03-17WIPDavid Majnemer1-1/+1
llvm-svn: 232537
2015-03-05MS ABI: Implement support for throwing a C++ exceptionDavid Majnemer1-96/+18
Throwing a C++ exception, under the MS ABI, is implemented using three components: - ThrowInfo structure which contains information like CV qualifiers, what destructor to call and a pointer to the CatchableTypeArray. - In a significant departure from the Itanium ABI, copying by-value occurs in the runtime and not at the catch site. This means we need to enumerate all possible types that this exception could be caught as and encode the necessary information to convert from the exception object's type to the catch handler's type. This includes complicated derived to base conversions and the execution of copy-constructors. N.B. This implementation doesn't support the execution of a copy-constructor from within the runtime for now. Adding support for that functionality is quite difficult due to things like default argument expressions which may evaluate arbitrary code hiding in the copy-constructor's parameters. Differential Revision: http://reviews.llvm.org/D8066 llvm-svn: 231328
2015-03-03Split catch IRgen into ItaniumCXXABI and MicrosoftCXXABIReid Kleckner1-381/+21
Use llvm.eh.begincatch for Microsoft-style catches. This moves lots of CGException code into ItaniumCXXABI. Sorry for the blame pain. llvm-svn: 231105
2015-02-26Don't crash on leaving nested __finally blocks through an EH edge.Nico Weber1-19/+12
The __finally emission block tries to be clever by removing unused continuation edges if there's an unconditional jump out of the __finally block. With exception edges, the EH continuation edge isn't always unused though and we'd crash in a few places. Just don't be clever. That makes the IR for __finally blocks a bit longer in some cases (hence small and behavior-preserving changes to existing tests), but it makes no difference in general and it fixes the last crash from PR22553. http://reviews.llvm.org/D7918 llvm-svn: 230697
2015-02-25MS ABI: Turn throw into std::terminate for now, make try/catch "work"David Majnemer1-7/+19
This lets us compile programs which make use of exceptional constructs statically without executing any of them dynamically. llvm-svn: 230568
2015-02-25Reland r230460 with a test fix for -Asserts builds.Nico Weber1-3/+4
Original CL description: Produce less broken basic block sequences for __finally blocks. The way cleanups (such as PerformSEHFinally) get emitted is that codegen generates some initialization code, then calls the cleanup's Emit() with the insertion point set to a good place, then the cleanup is supposed to emit its stuff, and then codegen might tack in a jump or similar to where the insertion point is after the cleanup. The PerformSEHFinally cleanup tries to just stash away the block it's supposed to codegen into, and then does codegen later, into that stashed block. However, after codegen'ing the __finally block, it used to set the insertion point to the finally's continuation block (where the __finally cleanup goes when its body is completed after regular, non-exceptional control flow). That's not correct, as that block can (and generally does) already ends in a jump. Instead, remember the insertion point that was current before the __finally got emitted, and restore that. Fixes two of the crashes in PR22553. llvm-svn: 230503
2015-02-25Revert "Produce less broken basic block sequences for __finally blocks."Daniel Jasper1-4/+3
The test is broken on buildbots: http://lab.llvm.org:8080/green/job/clang-stage2-configure-Rlto_check/2279/ This reverts commit adda738b6dc533c42db5f5f5b31344098a3aba7d. llvm-svn: 230472
2015-02-25Produce less broken basic block sequences for __finally blocks.Nico Weber1-3/+4
The way cleanups (such as PerformSEHFinally) get emitted is that codegen generates some initialization code, then calls the cleanup's Emit() with the insertion point set to a good place, then the cleanup is supposed to emit its stuff, and then codegen might tack in a jump or similar to where the insertion point is after the cleanup. The PerformSEHFinally cleanup tries to just stash away the block it's supposed to codegen into, and then does codegen later, into that stashed block. However, after codegen'ing the __finally block, it used to set the insertion point to the finally's continuation block (where the __finally cleanup goes when its body is completed after regular, non-exceptional control flow). That's not correct, as that block can (and generally does) already ends in a jump. Instead, remember the insertion point that was current before the __finally got emitted, and restore that. Fixes two of the crashes in PR22553. llvm-svn: 230460
2015-02-12SEH: Use the SEHTryEpilogueStack instead of a separate boolReid Kleckner1-5/+2
We don't need a bool to track this now that we have a stack for it. llvm-svn: 228982
2015-02-12[ms] Implement codegen for __leave.Nico Weber1-1/+18
Reviewed at http://reviews.llvm.org/D7575 llvm-svn: 228977
2015-02-11Wrap to 80 columns. No behavior change.Nico Weber1-3/+5
llvm-svn: 228880
2015-02-11Add the 'noinline' attribute to call sites within __try bodiesReid Kleckner1-1/+6
LLVM doesn't support non-call exceptions, so inlining makes it harder to catch such asynchronous exceptions. llvm-svn: 228876
2015-02-11Add a comdat to __clang_call_terminateReid Kleckner1-0/+2
llvm-svn: 228863
2015-02-11Emit landing pads for SEH even if nounwind is presentReid Kleckner1-2/+1
Disabling exceptions applies nounwind to lots of functions. SEH catches asynch exceptions, so emit the landing pad anyway. llvm-svn: 228769
2015-02-05Re-land r228258 and make clang-cl's /EHs- disable -fexceptions againReid Kleckner1-24/+32
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-05Revert r228258.Nico Weber1-22/+22
It caused a chromium base unittest that tests throwing and catching SEH exceptions to fail (http://crbug.com/455488) and I suspect it might also be the cause of the chromium clang win 64-bit shared release builder timing out during compiles. So revert to see if that's true. llvm-svn: 228262
2015-02-05Silence a warning.Sean Silva1-1/+1
/Users/Sean/pg/llvm/tools/clang/lib/CodeGen/CGException.cpp:1871:23: warning: unused variable 'Finally' [-Wunused-variable] if (SEHFinallyStmt *Finally = S.getFinallyHandler()) { ^ 1 warning generated. llvm-svn: 228255
2015-02-05Fix crash on finally blocks that don't fall throughReid Kleckner1-1/+9
llvm-svn: 228243
2015-02-04Implement IRGen for SEH __finally and AbnormalTerminationReid Kleckner1-12/+70
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-03SEH: Track users of __try so we can pick a per-func EH personalityReid Kleckner1-22/+22
There are four major kinds of declarations that cause code generation: - FunctionDecl (includes CXXMethodDecl etc) - ObjCMethodDecl - BlockDecl - CapturedDecl This patch tracks __try usage on FunctionDecls and diagnoses __try usage in other decls. If someone wants to use __try from ObjC, they can use it from a free function, since the ObjC code will need an ObjC-style EH personality. Eventually we will want to look through CapturedDecls and track SEH usage on the parent FunctionDecl, if present. llvm-svn: 228058
2015-02-03Address review feedback for r228003.Adrian Prantl1-1/+1
- use named constructors - get rid of MarkAsPrologue llvm-svn: 228021
2015-02-03Merge ArtificialLocation into ApplyDebugLocation and make a clearAdrian Prantl1-1/+1
distinction between the different use-cases. With the previous default behavior we would occasionally emit empty debug locations in situations where they actually were strictly required (= on invoke insns). We now have a choice between defaulting to an empty location or an artificial location. Specifically, this fixes a bug caused by a missing debug location when emitting C++ EH cleanup blocks from within an artificial function, such as an ObjC destroy helper function. rdar://problem/19670595 llvm-svn: 228003
2015-01-30SEH: Don't jump to an unreachable continuation blockReid Kleckner1-1/+2
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-22SEH: Emit the constant filter 1 as a catch-allReid Kleckner1-0/+12
Minor optimization of code like __try { ... } __except(1) { ... }. llvm-svn: 226766
2015-01-22Initial support for Win64 SEH IR emissionReid Kleckner1-4/+251
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-14[cleanup] Re-sort *all* #include lines with llvm/utils/sort_includes.pyChandler Carruth1-1/+1
Sorry for the noise, I managed to miss a bunch of recent regressions of include orderings here. This should actually sort all the includes for Clang. Again, no functionality changed, this is just a mechanical cleanup that I try to run periodically to keep the #include lines as regular as possible across the project. llvm-svn: 225979