aboutsummaryrefslogtreecommitdiff
path: root/clang/test/CodeGenObjC
AgeCommit message (Collapse)AuthorFilesLines
2017-06-30[objc] Don't require null-check and don't emit memset when result is ignored ↵Kuba Mracek2-1/+44
for struct-returning method calls [clang part] This fixes an issue with the emission of lifetime markers for struct-returning Obj-C msgSend calls. When the result of a struct-returning call is ignored, the temporary storage is only marked with lifetime markers in one of the two branches of the nil-receiver-check. The check is, however, not required when the result is unused. If we still need to emit the check (due to consumer arguments), let's not emit the memset to zero out the result if it's unused. This fixes a use-after-scope false positive with AddressSanitizer. Differential Revision: https://reviews.llvm.org/D34834 llvm-svn: 306837
2017-06-29CodeGen: handle missed case of COMDAT handlingSaleem Abdulrasool1-0/+8
When Protocol references are constructed, we need to add the reference symbol to a COMDAT group on non-MachO object file formats (MachO handles this by having a coalesced attribute). This adds the missing case. llvm-svn: 306622
2017-06-28[CodeGen] Fix assertion failure in EmitCallArg.Akira Hatanaka1-0/+28
The assertion was failing when a method of a parameterized class was called and the types of the argument and parameter didn't match. To fix the failure, move the assertion in EmitCallArg to its only caller EmitCallArgs and require the argument and parameter types match only when the method is not parameterized. rdar://problem/32874473 Differential Revision: https://reviews.llvm.org/D34665 llvm-svn: 306494
2017-06-27clang/test/CodeGenObjC/ivar-type-encoding.m: Tweak to satisfy -m32.NAKAMURA Takumi1-1/+1
llvm-svn: 306372
2017-06-27[CodeGen][ObjC] Fix GNU's encoding of bit-field ivars.Akira Hatanaka1-0/+16
According to the documentation, when encoding a bit-field, GNU runtime needs its starting position in addition to its type and size. https://gcc.gnu.org/onlinedocs/gcc/Type-encoding.html Prior to r297702, the starting position information was not being encoded, which is incorrect, and after r297702, an assertion started to fail because an ObjCIvarDecl was being passed to a function expecting a FieldDecl. This commit moves LookupFieldBitOffset to ASTContext and uses the function to encode the starting position of bit-fields. llvm-svn: 306364
2017-06-23[ubsan] Improve diagnostics for return value checks (clang)Vedant Kumar2-15/+51
This patch makes ubsan's nonnull return value diagnostics more precise, which makes the diagnostics more useful when there are multiple return statements in a function. Example: 1 |__attribute__((returns_nonnull)) char *foo() { 2 | if (...) { 3 | return expr_which_might_evaluate_to_null(); 4 | } else { 5 | return another_expr_which_might_evaluate_to_null(); 6 | } 7 |} // <- The current diagnostic always points here! runtime error: Null returned from Line 7, Column 2! With this patch, the diagnostic would point to either Line 3, Column 5 or Line 5, Column 5. This is done by emitting source location metadata for each return statement in a sanitized function. The runtime is passed a pointer to the appropriate metadata so that it can prepare and deduplicate reports. Compiler-rt patch (with more tests): https://reviews.llvm.org/D34298 Differential Revision: https://reviews.llvm.org/D34299 llvm-svn: 306163
2017-06-17CodeGen: make the type match the comment for a libcallSaleem Abdulrasool1-0/+16
Fix the type for a (runtime) library call to match both the comment and the runtime implementation. As it happens, the type being used matched, this just makes it more precise. llvm-svn: 305638
2017-06-12IR: Replace the "Linker Options" module flag with "llvm.linker.options" ↵Peter Collingbourne1-3/+2
named metadata. The new metadata is easier to manipulate than module flags. Differential Revision: https://reviews.llvm.org/D31349 llvm-svn: 305227
2017-06-03tests: silence -Wobjc-root-class warningsSaleem Abdulrasool3-7/+7
Silence warnings about no ObjC class root for the types defined for the tests. llvm-svn: 304662
2017-06-03CodeGen: fix section names for different file formatsSaleem Abdulrasool6-16/+88
This changes the codegen to match the section names according to the ObjC rewriter as well as the runtime. The changes to the test are simply whitespace changes to the section attributes and names and are functionally equivalent (the whitespace is ignored by the linker). llvm-svn: 304661
2017-06-01[CodeGen][ObjC] Fix assertion failure in EmitARCStoreStrongCall.Akira Hatanaka1-0/+28
The assertion fails because EmitValueForIvarAtOffset doesn't get the correct type of the ivar when the class the ivar belongs to is parameterized. This commit fixes the function to compute the ivar's type based on the type argument provided to the parameterized class. rdar://problem/32461723 Differential Revision: https://reviews.llvm.org/D33698 llvm-svn: 304449
2017-05-29IRGen: Add optnone attribute on function during O0Mehdi Amini1-1/+1
Amongst other, this will help LTO to correctly handle/honor files compiled with O0, helping debugging failures. It also seems in line with how we handle other options, like how -fnoinline adds the appropriate attribute as well. Differential Revision: https://reviews.llvm.org/D28404 llvm-svn: 304127
2017-05-09[CodeGen][ObjC] Emit @objc_retain at -O0 for variables captured byAkira Hatanaka2-2/+14
blocks. r302270 made changes to avoid emitting clang.arc.use at -O0 and instead emit @objc_release. We also have to emit @objc_retain for the captured variable at -O0 to match the @objc_release instead of just storing the pointer to the capture field. llvm-svn: 302495
2017-05-05CodeGen: avoid use of @clang.arc.use intrinsic at O0Saleem Abdulrasool1-7/+25
The clang.arc.use intrinsic is removed via the ARC Contract Pass. This pass is only executed in optimized builds (>= opt level 1). Prevent the optimization implemented in SVN r301667 from triggering at optimization level 0 like every other ARC use intrinsic usage. llvm-svn: 302270
2017-04-28[CodeGen][ObjC] Don't retain captured Objective-C pointers at blockAkira Hatanaka2-18/+37
creation that are const-qualified. When a block captures an ObjC object pointer, clang retains the pointer to prevent prematurely destroying the object the pointer points to before the block is called or copied. When the captured object pointer is const-qualified, we can avoid emitting the retain/release pair since the pointer variable cannot be modified in the scope in which the block literal is introduced. For example: void test(const id x) { callee(^{ (void)x; }); } This patch implements that optimization. rdar://problem/28894510 Differential Revision: https://reviews.llvm.org/D32601 llvm-svn: 301667
2017-04-26[ubsan] nullability-assign: Check assignments into C++ structsVedant Kumar1-20/+24
Fix the nullability-assign check so that it can handle assignments into C++ structs. Previously, such assignments were not instrumented. Testing: check-clang, check-ubsan, enabling the existing test in ObjC++ mode, and building some Apple frameworks with -fsanitize=nullability. llvm-svn: 301482
2017-04-17[ObjC] Mark loads from __NSArray0 and __NSDictionary0 as invariant.load.Akira Hatanaka1-1/+1
Also, simplify code by calling MakeNaturalAlignAddrLValue. This is a follow-up to r300396. llvm-svn: 300454
2017-04-15[ObjC] Use empty Objective-C collection literal constants whenAkira Hatanaka1-0/+51
available. Original patch by Douglas Gregor with minor modifications. This recommits r300389, which broke bots because there have been API changes since the original patch was written. rdar://problem/20689633 llvm-svn: 300396
2017-04-15Revert "[ObjC] Use empty Objective-C collection literal constants when"Akira Hatanaka1-51/+0
This reverts commit r300389. There were mistakes in the changes I made to CodeGen. llvm-svn: 300391
2017-04-15[ObjC] Use empty Objective-C collection literal constants whenAkira Hatanaka1-0/+51
available. Original patch by Douglas Gregor with minor modifications. rdar://problem/20689633 llvm-svn: 300389
2017-04-14[ObjC] Fix lifetime markers of loop variable in EmitObjCForCollectionStmt ↵Kuba Mracek1-3/+3
[take 2] CodeGenFunction::EmitObjCForCollectionStmt currently emits lifetime markers for the loop variable in an inconsistent way: lifetime.start is emitted before the loop is entered, but lifetime.end is emitted inside the loop. AddressSanitizer uses these markers to track out-of-scope accesses to local variables, and we get false positives in Obj-C foreach loops (in the 2nd iteration of the loop). This patch keeps the loop variable alive for the whole loop by extending ForScope and registering the cleanup function inside EmitAutoVarAlloca. Differential Revision: https://reviews.llvm.org/D32029 llvm-svn: 300340
2017-04-14Revert r300287.Kuba Mracek2-4/+4
llvm-svn: 300290
2017-04-14[ObjC] Fix lifetime markers of loop variable in EmitObjCForCollectionStmtKuba Mracek2-4/+4
CodeGenFunction::EmitObjCForCollectionStmt currently emits lifetime markers for the loop variable in an inconsistent way: lifetime.start is emitted before the loop is entered, but lifetime.end is emitted inside the loop. AddressSanitizer uses these markers to track out-of-scope accesses to local variables, and we get false positives in Obj-C foreach loops (in the 2nd iteration of the loop). The markers of the loop variable need to be either both inside the loop (so that we poison and unpoison the variable in each iteration), or both outside. This patch implements the "both inside" approach. Differential Revision: https://reviews.llvm.org/D32029 llvm-svn: 300287
2017-04-10Update for lifetime intrinsic signature changeMatt Arsenault5-98/+98
llvm-svn: 299877
2017-03-23[CodeGen] Emit a CoreFoundation link guard when @available is usedAlex Lorenz1-0/+45
After r297760, __isOSVersionAtLeast in compiler-rt loads the CoreFoundation symbols at runtime. This means that `@available` will always fail when used in a binary without a linked CoreFoundation. This commit forces Clang to emit a reference to a CoreFoundation symbol when `@available` is used to ensure that linking will fail when CoreFoundation isn't linked with the build product. rdar://31039592 Differential Revision: https://reviews.llvm.org/D30977 llvm-svn: 298588
2017-03-14[ubsan] Use the nicer nullability diagnostic handlersVedant Kumar1-7/+7
This is a follow-up to r297700 (Add a nullability sanitizer). It addresses some FIXME's re: using nullability-specific diagnostic handlers from compiler-rt, now that the necessary handlers exist. check-ubsan test updates to follow. llvm-svn: 297750
2017-03-14[CodeGen][ObjC] Fix a bug where the type of an ivar wasn't encodedAkira Hatanaka1-0/+35
correctly. This fixes PR30413. Patch by David Lobron. llvm-svn: 297702
2017-03-14[ubsan] Add a nullability sanitizerVedant Kumar2-0/+213
Teach UBSan to detect when a value with the _Nonnull type annotation assumes a null value. Call expressions, initializers, assignments, and return statements are all checked. Because _Nonnull does not affect IRGen, the new checks are disabled by default. The new driver flags are: -fsanitize=nullability-arg (_Nonnull violation in call) -fsanitize=nullability-assign (_Nonnull violation in assignment) -fsanitize=nullability-return (_Nonnull violation in return stmt) -fsanitize=nullability (all of the above) This patch builds on top of UBSan's existing support for detecting violations of the nonnull attributes ('nonnull' and 'returns_nonnull'), and relies on the compiler-rt support for those checks. Eventually we will need to update the diagnostic messages in compiler-rt (there are FIXME's for this, which will be addressed in a follow-up). One point of note is that the nullability-return check is only allowed to kick in if all arguments to the function satisfy their nullability preconditions. This makes it necessary to emit some null checks in the function body itself. Testing: check-clang and check-ubsan. I also built some Apple ObjC frameworks with an asserts-enabled compiler, and verified that we get valid reports. Differential Revision: https://reviews.llvm.org/D30762 llvm-svn: 297700
2017-03-09Retry: [ubsan] Detect UB loads from bitfieldsVedant Kumar1-2/+55
It's possible to load out-of-range values from bitfields backed by a boolean or an enum. Check for UB loads from bitfields. This is the motivating example: struct S { BOOL b : 1; // Signed ObjC BOOL. }; S s; s.b = 1; // This is actually stored as -1. if (s.b == 1) // Evaluates to false, -1 != 1. ... Changes since the original commit: - Single-bit bools are a special case (see CGF::EmitFromMemory), and we can't avoid dealing with them when loading from a bitfield. Don't try to insert a check in this case. Differential Revision: https://reviews.llvm.org/D30423 llvm-svn: 297389
2017-03-09Revert "[ubsan] Detect UB loads from bitfields"Vedant Kumar1-55/+2
This reverts commit r297298. It breaks the self-host on this bot: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/962/steps/build%20clang%2Fubsan/logs/stdio llvm-svn: 297331
2017-03-08[ubsan] Detect UB loads from bitfieldsVedant Kumar1-2/+55
It's possible to load out-of-range values from bitfields backed by a boolean or an enum. Check for UB loads from bitfields. This is the motivating example: struct S { BOOL b : 1; // Signed ObjC BOOL. }; S s; s.b = 1; // This is actually stored as -1. if (s.b == 1) // Evaluates to false, -1 != 1. ... Differential Revision: https://reviews.llvm.org/D30423 llvm-svn: 297298
2017-03-06[ubsan] Extend the nonnull arg check to ObjCVedant Kumar1-0/+48
UBSan's nonnull argument check applies when a parameter has the "nonnull" attribute. The check currently works for FunctionDecls, but not for ObjCMethodDecls. This patch extends the check to work for ObjC. Differential Revision: https://reviews.llvm.org/D30599 llvm-svn: 296996
2017-02-24NFC, Add a test that ensures that we don't emit helper code in copy/disposeAlex Lorenz1-0/+35
routines for objects that are captured with the __unsafe_unretained ownership qualifier This is a preparation commit that improves code-coverage in code that emits block copy/dispose routines. llvm-svn: 296048
2017-02-23[ObjC][CodeGen] CodeGen support for @available.Erik Pilkington1-0/+31
CodeGens uses of @available into calls to the compiler-rt function __isOSVersionAtLeast. This commit is part of a feature that I proposed here: http://lists.llvm.org/pipermail/cfe-dev/2016-July/049851.html Differential revision: https://reviews.llvm.org/D27827 llvm-svn: 296015
2017-02-21Only enable AddDiscriminator pass when -fdebug-info-for-profiling is trueDehao Chen1-3/+2
Summary: AddDiscriminator pass is only useful for sample pgo. This patch restricts AddDiscriminator to -fdebug-info-for-profiling so that it does not introduce unecessary debug size increases for non-sample-pgo builds. Reviewers: dblaikie, aprantl Reviewed By: dblaikie Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D30220 llvm-svn: 295764
2017-02-11CodeGen: annotate ObjC ARC functions with ABI constraintsSaleem Abdulrasool1-11/+13
Certain ARC runtime functions have an ABI contract of being forwarding. Annotate the functions with the appropriate `returned` attribute on the arguments. This hoists some of the runtime ABI contract information into the frontend rather than the backend transformations. The test adjustments are to mark the returned function parameter as such. The minor change to the IR output is due to the fact that the returned reference of the object causes it to extend the lifetime of the object by returning an autoreleased return value. The result is that the explicit objc_autorelease call is no longer formed, as autorelease elision is now possible on the return. llvm-svn: 294872
2017-02-11test: ignore some warnings in test code (NFC)Saleem Abdulrasool1-4/+4
Silence some diagnostics which clang now generates. This makes it easier to see the failures in lit output. NFC. llvm-svn: 294871
2017-02-01[CodeGen][ObjC] Avoid asserting on block pointer types inAlex Lorenz1-0/+28
isPointerZeroInitializable rdar://30111891 llvm-svn: 293787
2017-01-31Handle ObjCEncodeExpr in extractStringLiteralCharacter.Akira Hatanaka1-0/+11
This fixes an assertion failure that occurs later in the function when an ObjCEncodeExpr is cast to StringLiteral. rdar://problem/30111207 llvm-svn: 293596
2016-12-23Cleanup the handling of noinline function attributes, -fno-inline,Chandler Carruth2-2/+2
-fno-inline-functions, -O0, and optnone. These were really, really tangled together: - We used the noinline LLVM attribute for -fno-inline - But not for -fno-inline-functions (breaking LTO) - But we did use it for -finline-hint-functions (yay, LTO is happy!) - But we didn't for -O0 (LTO is sad yet again...) - We had weird structuring of CodeGenOpts with both an inlining enumeration and a boolean. They interacted in weird ways and needlessly. - A *lot* of set smashing went on with setting these, and then got worse when we considered optnone and other inlining-effecting attributes. - A bunch of inline affecting attributes were managed in a completely different place from -fno-inline. - Even with -fno-inline we failed to put the LLVM noinline attribute onto many generated function definitions because they didn't show up as AST-level functions. - If you passed -O0 but -finline-functions we would run the normal inliner pass in LLVM despite it being in the O0 pipeline, which really doesn't make much sense. - Lastly, we used things like '-fno-inline' to manipulate the pass pipeline which forced the pass pipeline to be much more parameterizable than it really needs to be. Instead we can *just* use the optimization level to select a pipeline and control the rest via attributes. Sadly, this causes a bunch of churn in tests because we don't run the optimizer in the tests and check the contents of attribute sets. It would be awesome if attribute sets were a bit more FileCheck friendly, but oh well. I think this is a significant improvement and should remove the semantic need to change what inliner pass we run in order to comply with the requested inlining semantics by relying completely on attributes. It also cleans up tho optnone and related handling a bit. One unfortunate aspect of this is that for generating alwaysinline routines like those in OpenMP we end up removing noinline and then adding alwaysinline. I tried a bunch of other approaches, but because we recompute function attributes from scratch and don't have a declaration here I couldn't find anything substantially cleaner than this. Differential Revision: https://reviews.llvm.org/D28053 llvm-svn: 290398
2016-12-23Make '-disable-llvm-optzns' an alias for '-disable-llvm-passes'.Chandler Carruth12-15/+15
Much to my surprise, '-disable-llvm-optzns' which I thought was the magical flag I wanted to get at the raw LLVM IR coming out of Clang deosn't do that. It still runs some passes over the IR. I don't want that, I really want the *raw* IR coming out of Clang and I strongly suspect everyone else using it is in the same camp. There is actually a flag that does what I want that I didn't know about called '-disable-llvm-passes'. I suspect many others don't know about it either. It both does what I want and is much simpler. This removes the confusing version and makes that spelling of the flag an alias for '-disable-llvm-passes'. I've also moved everything in Clang to use the 'passes' spelling as it seems both more accurate (*all* LLVM passes are disabled, not just optimizations) and much easier to remember and spell correctly. This is part of simplifying how Clang drives LLVM to make it cleaner to wire up to the new pass manager. Differential Revision: https://reviews.llvm.org/D28047 llvm-svn: 290392
2016-12-19Add a lit test for PR31374Yaxun Liu1-0/+22
Differential Revision: https://reviews.llvm.org/D27909 llvm-svn: 290075
2016-12-13[CodeGen][ObjC] Emit objc_unsafeClaimAutoreleasedReturnValue forAkira Hatanaka1-0/+3
fragile runtime too. Follow-up to r258962. rdar://problem/29269006 llvm-svn: 289615
2016-12-09[ubsan] Treat ObjC's BOOL as if its range is always {0, 1}Vedant Kumar1-0/+13
On some Apple platforms, the ObjC BOOL type is defined as a signed char. When performing instrumentation for -fsanitize=bool, we'd like to treat the range of BOOL like it's always {0, 1}. While we can't change clang's IRGen for char-backed BOOL's due to ABI compatibility concerns, we can teach ubsan to catch potential abuses of this type. rdar://problem/29502773 Differential Revision: https://reviews.llvm.org/D27607 llvm-svn: 289290
2016-11-30Switch CGObjCMac to use ConstantInitBuilder. Whew.John McCall2-5/+4
Not strictly NFC because I did change the order of emission of some global constants, but it shouldn't make any difference. llvm-svn: 288229
2016-11-16Improve handling of __FUNCTION__ and other predefined expression for ↵Mehdi Amini1-3/+2
Objective-C Blocks Instead of always displaying the mangled name, try to do better and get something closer to regular functions. Recommit r287039 (that was reverted in r287039) with a tweak to be more generic, and test fixes! Differential Revision: https://reviews.llvm.org/D26522 llvm-svn: 287085
2016-10-25CodeGen: be more conservative about setting sectionSaleem Abdulrasool1-0/+45
The section names currently are MachO specific. Only set the section on the variables if the file format is MachO. llvm-svn: 285126
2016-10-25CodeGen: mark protocols as common dataSaleem Abdulrasool1-0/+20
This allows for the coalescing of the protocol declarations. When the protocols are declared in headers, multiple definitions of the protocol would be emitted. Marking them as common data indicates that any one can be selected. llvm-svn: 285073
2016-10-24Add support for __builtin_os_log_format[_buffer_size]Mehdi Amini1-0/+39
This reverts commit r285007 and reapply r284990, with a fix for the opencl test that I broke. Original commit message follows: These new builtins support a mechanism for logging OS events, using a printf-like format string to specify the layout of data in a buffer. The _buffer_size version of the builtin can be used to determine the size of the buffer to allocate to hold the data, and then __builtin_os_log_format can write data into that buffer. This implements format checking to report mismatches between the format string and the data arguments. Most of this code was written by Chris Willmore. Differential Revision: https://reviews.llvm.org/D25888 llvm-svn: 285019
2016-10-24Revert "Add support for __builtin_os_log_format[_buffer_size]"Mehdi Amini1-39/+0
This reverts commit r284990, two opencl test are broken llvm-svn: 285007