summaryrefslogtreecommitdiffstats
path: root/clang/test/CodeGen/object-size.c
Commit message (Collapse)AuthorAgeFilesLines
* [opaque pointer types] Cleanup CGBuilder's Create*GEP.James Y Knight2019-02-081-15/+15
| | | | | | | | | | | | | | | | | | | | | | | Some of these functions take some extraneous arguments, e.g. EltSize, Offset, which are computable from the Type and DataLayout. Add some asserts to ensure that the computed values are consistent with the passed-in values, in preparation for eliminating the extraneous arguments. This also asserts that the Type is an Array for the calls named "Array" and a Struct for the calls named "Struct". Then, correct a couple of errors: 1. Using CreateStructGEP on an array type. (this causes the majority of the test differences, as struct GEPs are created with i32 indices, while array GEPs are created with i64 indices) 2. Passing the wrong Offset to CreateStructGEP in TargetInfo.cpp on x86-64 NACL (which uses 32-bit pointers). Differential Revision: https://reviews.llvm.org/D57766 llvm-svn: 353529
* Add a new builtin: __builtin_dynamic_object_sizeErik Pilkington2019-01-301-139/+146
| | | | | | | | | | | | | | | | | | | | | | | | | This builtin has the same UI as __builtin_object_size, but has the potential to be evaluated dynamically. It is meant to be used as a drop-in replacement for libraries that use __builtin_object_size when a dynamic checking mode is enabled. For instance, __builtin_object_size fails to provide any extra checking in the following function: void f(size_t alloc) { char* p = malloc(alloc); strcpy(p, "foobar"); // expands to __builtin___strcpy_chk(p, "foobar", __builtin_object_size(p, 0)) } This is an overflow if alloc < 7, but because LLVM can't fold the object size intrinsic statically, it folds __builtin_object_size to -1. With __builtin_dynamic_object_size, alloc is passed through to __builtin___strcpy_chk. rdar://32212419 Differential revision: https://reviews.llvm.org/D56760 llvm-svn: 352665
* Add a 'dynamic' parameter to the objectsize intrinsicErik Pilkington2019-01-301-55/+55
| | | | | | | | | | | | | | This is meant to be used with clang's __builtin_dynamic_object_size. When 'true' is passed to this parameter, the intrinsic has the potential to be folded into instructions that will be evaluated at run time. When 'false', the objectsize intrinsic behaviour is unchanged. rdar://32212419 Differential revision: https://reviews.llvm.org/D56761 llvm-svn: 352664
* Let llvm.objectsize be conservative with null pointersGeorge Burgess IV2017-03-211-55/+55
| | | | | | | D28494 adds another parameter to @llvm.objectsize. Clang needs to be sure to pass that third arg whenever applicable. llvm-svn: 298431
* Don't let EvaluationModes dictate whether an invalid base is OKGeorge Burgess IV2017-02-101-0/+19
| | | | | | | | | | | | What we want to actually control this behavior is something more local than an EvalutationMode. Please see the linked revision for more discussion on why/etc. This fixes PR31843. Differential Revision: https://reviews.llvm.org/D29469 llvm-svn: 294800
* Re-add objectsize function/incomplete type checks.George Burgess IV2017-01-031-0/+13
| | | | | | | I accidentally omitted these when refactoring this code. This caused problems when building parts of the test-suite on MacOS. llvm-svn: 290916
* [Sema] Fix PR30346: relax __builtin_object_size checks.George Burgess IV2016-09-121-3/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch makes us act more conservatively when trying to determine the objectsize for an array at the end of an object. This is in response to code like the following: ``` struct sockaddr { /* snip */ char sa_data[14]; }; void foo(const char *s) { size_t slen = strlen(s) + 1; size_t added_len = slen <= 14 ? 0 : slen - 14; struct sockaddr *sa = malloc(sizeof(struct sockaddr) + added_len); strcpy(sa->sa_data, s); // ... } ``` `__builtin_object_size(sa->sa_data, 1)` would return 14, when there could be more than 14 bytes at `sa->sa_data`. Code like this is apparently not uncommon. FreeBSD's manual even explicitly mentions this pattern: https://www.freebsd.org/doc/en/books/developers-handbook/sockets-essential-functions.html (section 7.5.1.1.2). In light of this, we now just give up on any array at the end of an object if we can't find the object's initial allocation. I lack numbers for how much more conservative we actually become as a result of this change, so I chose the fix that would make us as compatible with GCC as possible. If we want to be more aggressive, I'm happy to consider some kind of whitelist or something instead. llvm-svn: 281277
* Fix typo in test/CodeGen/object-size.c CHECK line.Bob Wilson2016-02-241-1/+1
| | | | llvm-svn: 261762
* Make __builtin_object_size more conservativeGeorge Burgess IV2015-10-161-12/+138
| | | | | | | | | | | | | | | | | | | | | | | | | | | r246877 made __builtin_object_size substantially more aggressive with unknown bases if Type=1 or Type=3, which causes issues when we encounter code like this: struct Foo { int a; char str[1]; }; const char str[] = "Hello, World!"; struct Foo *f = (struct Foo *)malloc(sizeof(*f) + strlen(str)); strcpy(&f->str, str); __builtin_object_size(&f->str, 1) would hand back 1, which is technically correct given the type of Foo, but the type of Foo lies to us about how many bytes are available in this case. This patch adds support for this "writing off the end" idiom -- we now answer conservatively when we're given the address of the very last member in a struct. Differential Revision: http://reviews.llvm.org/D12169 llvm-svn: 250488
* Compute and preserve alignment more faithfully in IR-generation.John McCall2015-09-081-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Introduce an Address type to bundle a pointer value with an alignment. Introduce APIs on CGBuilderTy to work with Address values. Change core APIs on CGF/CGM to traffic in Address where appropriate. Require alignments to be non-zero. Update a ton of code to compute and propagate alignment information. As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment helper function to CGF and made use of it in a number of places in the expression emitter. The end result is that we should now be significantly more correct when performing operations on objects that are locally known to be under-aligned. Since alignment is not reliably tracked in the type system, there are inherent limits to this, but at least we are no longer confused by standard operations like derived-to-base conversions and array-to-pointer decay. I've also fixed a large number of bugs where we were applying the complete-object alignment to a pointer instead of the non-virtual alignment, although most of these were hidden by the very conservative approach we took with member alignment. Also, because IRGen now reliably asserts on zero alignments, we should no longer be subject to an absurd but frustrating recurring bug where an incomplete type would report a zero alignment and then we'd naively do a alignmentAtOffset on it and emit code using an alignment equal to the largest power-of-two factor of the offset. We should also now be emitting much more aggressive alignment attributes in the presence of over-alignment. In particular, field access now uses alignmentAtOffset instead of min. Several times in this patch, I had to change the existing code-generation pattern in order to more effectively use the Address APIs. For the most part, this seems to be a strict improvement, like doing pointer arithmetic with GEPs instead of ptrtoint. That said, I've tried very hard to not change semantics, but it is likely that I've failed in a few places, for which I apologize. ABIArgInfo now always carries the assumed alignment of indirect and indirect byval arguments. In order to cut down on what was already a dauntingly large patch, I changed the code to never set align attributes in the IR on non-byval indirect arguments. That is, we still generate code which assumes that indirect arguments have the given alignment, but we don't express this information to the backend except where it's semantically required (i.e. on byvals). This is likely a minor regression for those targets that did provide this information, but it'll be trivial to add it back in a later patch. I partially punted on applying this work to CGBuiltin. Please do not add more uses of the CreateDefaultAligned{Load,Store} APIs; they will be going away eventually. llvm-svn: 246985
* Increase accuracy of __builtin_object_size.George Burgess IV2015-09-041-4/+115
| | | | | | | | | | | | | | | | | | | Improvements: - For all types, we would give up in a case such as: __builtin_object_size((char*)&foo, N); even if we could provide an answer to __builtin_object_size(&foo, N); We now provide the same answer for both of the above examples in all cases. - For type=1|3, we now support subobjects with unknown bases, as long as the designator is valid. Thanks to Richard Smith for the review + design planning. Review: http://reviews.llvm.org/D12169 llvm-svn: 246877
* Fix CHECK directives that weren't checking.Hans Wennborg2015-08-311-2/+2
| | | | llvm-svn: 246492
* Make __builtin_object_size always answer correctlyGeorge Burgess IV2015-08-191-0/+134
| | | | | | | | | | | | | | | | | | __builtin_object_size would return incorrect answers for many uses where type=3. This fixes the inaccuracy by making us emit 0 instead of LLVM's objectsize intrinsic. Additionally, there are many cases where we would emit suboptimal (but correct) answers, such as when arrays are involved. This patch fixes some of these cases (please see new tests in test/CodeGen/object-size.c for specifics on which cases are improved) Resubmit of r245323 with PR24493 fixed. Patch mostly by Richard Smith. Differential Revision: http://reviews.llvm.org/D12000 This fixes PR15212. llvm-svn: 245403
* Revert r245323, it caused PR24493.Nico Weber2015-08-181-93/+0
| | | | llvm-svn: 245342
* Make __builtin_object_size always answer correctlyGeorge Burgess IV2015-08-181-0/+93
| | | | | | | | | | | | | | | | | __builtin_object_size would return incorrect answers for many uses where type=3. This fixes the inaccuracy by making us emit 0 instead of LLVM's objectsize intrinsic. Additionally, there are many cases where we would emit suboptimal (but correct) answers, such as when arrays are involved. This patch fixes some of these cases (please see new tests in test/CodeGen/object-size.c for specifics on which cases are improved) Patch mostly by Richard Smith. Differential Revision: http://reviews.llvm.org/D12000 This fixes PR15212. llvm-svn: 245323
* Test case updates for explicit type parameter to the gep operatorDavid Blaikie2015-03-131-15/+15
| | | | llvm-svn: 232187
* Update Clang tests to handle explicitly typed load changes in LLVM.David Blaikie2015-02-271-1/+1
| | | | llvm-svn: 230795
* Fix objectsize tests after r192117Matt Arsenault2013-10-071-1/+1
| | | | llvm-svn: 192120
* CHECK-LABEL-ify some code gen tests to improve diagnostic experience when ↵Stephen Lin2013-08-151-16/+16
| | | | | | tests fail. llvm-svn: 188447
* add support for conditional expressions in Expr::HasSideEffects()Nuno Lopes2012-07-131-1/+10
| | | | | | This fixes a bug in __builtin_object_size() codegen llvm-svn: 160191
* If the first argument of __builtin_object_size can be folded to a constantRichard Smith2012-05-231-1/+4
| | | | | | | | pointer, but such folding encounters side-effects, ignore the side-effects rather than performing them at runtime: CodeGen generates wrong code for __builtin_object_size in that case. llvm-svn: 157310
* revert the usage of the objectsize intrinsic with 3 parameters (to match ↵Nuno Lopes2012-05-221-2/+2
| | | | | | LLVM r157255) llvm-svn: 157256
* update calls to objectsize intrinsic to match LLVM r156473Nuno Lopes2012-05-091-2/+2
| | | | | | add a test for -fbounds-checking code generation llvm-svn: 156474
* Constant expression evaluation: add support for evaluation of member pointersRichard Smith2011-11-171-2/+1
| | | | | | and base-to-derived casts, and add proper handling of temporaries. llvm-svn: 144926
* IRgen: Assignment to Objective-C properties shouldn't reload the value (whichDaniel Dunbar2010-06-291-1/+17
| | | | | | | | would trigger an extra method call). - While in the area, I also changed Clang to not emit an unnecessary load from 'x' in cases like 'y = (x = 1)'. llvm-svn: 107210
* Fix for Release-Asserts.Mike Stump2010-01-131-18/+17
| | | | llvm-svn: 93340
* __builtin_object_size(ptr, type) returns -1 for type = {0,1} if there are ↵Benjamin Kramer2010-01-031-0/+11
| | | | | | any side-effects. llvm-svn: 92453
* Update for the intrinsic changes in llvm: the object size intrinsicEric Christopher2009-12-231-1/+1
| | | | | | | only takes a boolean second argument now. Update tests accordingly. Currently the builtin still accepts the full range for compatibility. llvm-svn: 91983
* Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'.Daniel Dunbar2009-12-151-1/+1
| | | | | | | | | - This is designed to make it obvious that %clang_cc1 is a "test variable" which is substituted. It is '%clang_cc1' instead of '%clang -cc1' because it can be useful to redefine what gets run as 'clang -cc1' (for example, to set a default target). llvm-svn: 91446
* Switch over to checking .ll files instead of .s files.Mike Stump2009-12-071-44/+29
| | | | llvm-svn: 90786
* Fix tests after enabling -split-phi-edges.Jakob Stoklund Olesen2009-11-171-10/+10
| | | | | | | | object-size.c aws simply too fragile. constructor-default-arg.cpp triggers an issue when LiveVariables is run before RALocal. llvm-svn: 89025
* Enable the use of the new llvm objectsize intrinsic.Mike Stump2009-11-091-2/+2
| | | | llvm-svn: 86607
* Add missing colons for FileCheck.Benjamin Kramer2009-10-311-1/+1
| | | | llvm-svn: 85683
* Fix one more bug with __builtin_object_size.Mike Stump2009-10-291-0/+6
| | | | llvm-svn: 85538
* Add yet more testcases.Mike Stump2009-10-291-0/+30
| | | | llvm-svn: 85535
* Add some more testcases.Mike Stump2009-10-291-6/+30
| | | | llvm-svn: 85534
* Make test independent of darwin system headers.Benjamin Kramer2009-10-271-3/+10
| | | | llvm-svn: 85232
* __builtin_object_size refinements. Also handle stack based objects. WIP.Mike Stump2009-10-261-0/+10
| | | | llvm-svn: 85174
* __builtin_object_size refinements. When we run out of object, be sureMike Stump2009-10-261-3/+19
| | | | | | to clamp at 0 bytes left. WIP. llvm-svn: 85157
* __builtin_object_size refinements. WIP.Mike Stump2009-10-261-0/+33
llvm-svn: 85136
OpenPOWER on IntegriCloud