llvm-project/clang/test
Pierre Habouzit d18fbfc097 Relax the rules around objc_alloc and objc_alloc_init optimizations.
Today the optimization is limited to:
- `[ClassName alloc]`
- `[self alloc]` when within a class method

However it means that when code is written this way:

```
    @interface MyObject
    - (id)copyWithZone:(NSZone *)zone
    {
        return [[self.class alloc] _initWith...];
    }

    @end
```

... then the optimization doesn't kick in and `+[NSObject alloc]` ends
up in IMP caches where it could have been avoided. It turns out that
`+alloc` -> `+[NSObject alloc]` is the most cached SEL/IMP pair in the
entire platform which is rather silly).

There's two theoretical risks allowing this optimization:

1. if the receiver is nil (which it can't be today), but it turns out
   that `objc_alloc()`/`objc_alloc_init()` cope with a nil receiver,

2. if the `Clas` type for the receiver is a lie. However, for such a
   code to work today (and not fail witn an unrecognized selector
   anyway) you'd have to have implemented the `-alloc` **instance
   method**.

   Fortunately, `objc_alloc()` doesn't assume that the receiver is a
   Class, it basically starts with a test that is similar to

       `if (receiver->isa->bits & hasDefaultAWZ) { /* fastpath */ }`.

   This bit is only set on metaclasses by the runtime, so if an instance
   is passed to this function by accident, its isa will fail this test,
   and `objc_alloc()` will gracefully fallback to `objc_msgSend()`.

   The one thing `objc_alloc()` doesn't support is tagged pointer
   instances. None of the tagged pointer classes implement an instance
   method called `'alloc'` (actually there's a single class in the
   entire Apple codebase that has such a method).

Differential Revision: https://reviews.llvm.org/D71682
Radar-Id: rdar://problem/58058316
Reviewed-By: Akira Hatanaka
Signed-off-by: Pierre Habouzit <phabouzit@apple.com>
2020-01-14 19:48:33 -08:00
..
ARCMT
AST Disallow an empty string literal in an asm label 2020-01-08 08:38:02 -05:00
ASTMerge
Analysis [analyzer] Fix SARIF column locations 2020-01-14 15:38:30 -05:00
CXX PR44540: Prefer an inherited default constructor over an initializer 2020-01-14 19:29:50 -08:00
ClangScanDeps Revert "[clang][clang-scan-deps] Aggregate the full dependency information." 2019-12-11 16:35:55 -08:00
CodeCompletion [CodeComplete] Suggest 'return nullptr' in functions returning pointers 2020-01-10 13:28:13 +01:00
CodeGen [X86] ABI compat bugfix for MSVC vectorcall 2020-01-14 17:49:13 -08:00
CodeGenCUDA [HIP] Add option --gpu-max-threads-per-block=n 2020-01-07 11:18:00 -05:00
CodeGenCXX [DebugInfo] Add option to clang to limit debug info that is emitted for classes. 2020-01-14 12:40:21 -08:00
CodeGenCoroutines
CodeGenObjC Relax the rules around objc_alloc and objc_alloc_init optimizations. 2020-01-14 19:48:33 -08:00
CodeGenObjCXX Debug Info: Strengthen the synthesized-property-cleanup.mm test, NFC 2019-12-10 13:39:22 -08:00
CodeGenOpenCL [OpenCL] Fix mangling of single-overload builtins 2019-12-03 11:09:16 +00:00
CodeGenOpenCLCXX [OpenCL] Add ExtVectorElementExpr constant evaluation (PR42387) 2019-12-17 11:10:06 +00:00
Coverage
CoverageMapping Revert "[Coverage] Revise format to reduce binary size" 2019-12-04 10:35:14 -08:00
Driver Modify test to use -S instead of -c so that it works when an external assembler is used that is not present. 2020-01-14 18:58:18 -08:00
FixIt
Format
Frontend [clang][test][NFC] Use more widely supported sanitizer for file dependency tests 2020-01-14 12:55:11 -08:00
Headers [X86] Mark various pointer arguments in builtins as const 2019-12-19 11:42:11 -08:00
Import Tighten up CHECK lines added in a9f10ebffa to work on ARM. 2019-12-05 18:35:08 -08:00
Index [OpenCL] Pretty print __private addr space 2019-12-27 13:42:07 +00:00
Integration
InterfaceStubs try to fix InterfaceStubs/lambda.cpp on Windows after bd8c8827d9 2020-01-13 21:22:46 -05:00
Layout
Lexer Fix crash on init-capture packs where the type of the initializer is non-dependent. 2019-12-19 15:20:10 -08:00
Misc Remove umask tests 2020-01-10 21:05:59 -05:00
Modules make -fmodules-codegen and -fmodules-debuginfo work also with PCHs 2020-01-15 00:01:08 +01:00
OpenMP [OPENMP]Do not emit special virtual function for NVPTX target. 2020-01-14 16:59:22 -05:00
PCH Allow /D flags absent during PCH creation under msvc-compat 2020-01-14 17:26:01 -08:00
Parser [Concepts] Type Constraints 2020-01-15 04:02:39 +02:00
Preprocessor [RISCV] Add Clang frontend support for Bitmanip extension 2020-01-14 17:45:45 +00:00
Profile Revert "[Coverage] Revise format to reduce binary size" 2019-12-04 10:35:14 -08:00
Refactor
Rewriter
Sema Implement VectorType conditional operator GNU extension. 2020-01-13 13:27:20 -08:00
SemaCUDA
SemaCXX PR44514: Fix recovery from noexcept with non-convertible expressions 2020-01-13 13:51:48 -08:00
SemaObjC Add a FIXME and corresponding test coverage for some suspicious behavior 2020-01-10 16:12:00 -08:00
SemaObjCXX Clean up and slightly generalize implementation of composite pointer 2020-01-10 16:12:00 -08:00
SemaOpenCL CWG2352: Allow qualification conversions during reference binding. 2020-01-09 18:24:06 -08:00
SemaOpenCLCXX Clean up and slightly generalize implementation of composite pointer 2020-01-10 16:12:00 -08:00
SemaSYCL [SYCL] Add sycl_kernel attribute for accelerated code outlining 2019-12-03 16:13:22 +03:00
SemaTemplate [Concepts] Type Constraints 2020-01-15 04:02:39 +02:00
TableGen
Templight
Tooling
Unit
VFS Fix external-names.c test when separator is \\ 2019-12-31 11:15:46 +00:00
clang-rename
.clang-format
CMakeLists.txt [Clang][Driver] Re-use the calling process instead of creating a new process for the cc1 invocation 2020-01-13 10:40:18 -05:00
TestRunner.sh
cxx-sections.data
lit.cfg.py Revert "[analyzer] Add test directory for scan-build." 2019-11-05 14:03:36 -08:00
lit.site.cfg.py.in build: reduce CMake handling for zlib 2020-01-02 11:19:12 -08:00
make_test_dirs.pl