Commit Graph

812 Commits

Author SHA1 Message Date
Alex Lorenz b14b766b1c [ObjC] Error out when using forward-declared protocol in a @protocol
expression

Clang emits invalid protocol metadata when a @protocol expression is used with a
forward-declared protocol. The protocol metadata is missing protocol conformance
list of the protocol since we don't have access to the definition of it in the
compiled translation unit. The linker then might end up picking the invalid
metadata when linking which will lead to incorrect runtime protocol conformance
checks.

This commit makes sure that Clang fails to compile code that uses a @protocol
expression with a forward-declared protocol. This ensures that Clang does not
emit invalid protocol metadata. I added an extra assert in CodeGen to ensure
that this kind of issue won't happen in other places.

rdar://32787811

Differential Revision: https://reviews.llvm.org/D49462


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@340102 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-17 22:18:08 +00:00
Akira Hatanaka 0e6cfa4e8a [CodeGen] Merge identical block descriptor global variables.
Currently, clang generates a new block descriptor global variable for
each new block literal. This commit merges block descriptors that are
identical inside and across translation units using the same approach
taken in r339438.

To enable merging identical block descriptors, the size and signature of
the block and information about the captures are encoded into the name
of the block descriptor variable. Also, the block descriptor variable is
marked as linkonce_odr and unnamed_addr.

rdar://problem/42640703

Differential Revision: https://reviews.llvm.org/D50783

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@340041 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-17 15:46:07 +00:00
Fangrui Song abdbb605f2 Remove trailing space
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338291 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-30 19:24:48 +00:00
Adrian Prantl 647be32c60 Remove \brief commands from doxygen comments.
This is similar to the LLVM change https://reviews.llvm.org/D46290.

We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done

Differential Revision: https://reviews.llvm.org/D46320

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@331834 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-09 01:00:01 +00:00
Alexander Kornienko b8b9458165 Fix typos in clang
Found via codespell -q 3 -I ../clang-whitelist.txt
Where whitelist consists of:

  archtype
  cas
  classs
  checkk
  compres
  definit
  frome
  iff
  inteval
  ith
  lod
  methode
  nd
  optin
  ot
  pres
  statics
  te
  thru

Patch by luzpaz! (This is a subset of D44188 that applies cleanly with a few
files that have dubious fixes reverted.)

Differential revision: https://reviews.llvm.org/D44188

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@329399 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-06 15:14:32 +00:00
Akira Hatanaka 8a96d34fb2 [ObjC] Use the name specified by objc_runtime_name instead of the class
identifier.

This patch fixes a few places in CGObjCMac.cpp where the class
identifier was used instead of the name specified by objc_runtime_name.

rdar://problem/37910822

Differential Revision: https://reviews.llvm.org/D45101

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@329128 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-03 22:50:16 +00:00
Yaxun Liu a25e503459 Recommit r326946 after reducing CallArgList memory footprint
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@327634 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-15 15:25:19 +00:00
Richard Smith 5034f5fdda Revert r326946. It caused stack overflows by significantly increasing the size of a CallArgList.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@327195 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-10 01:47:22 +00:00
Yaxun Liu 8e23619931 CodeGen: Fix address space of indirect function argument
The indirect function argument is in alloca address space in LLVM IR. However,
during Clang codegen for C++, the address space of indirect function argument
should match its address space in the source code, i.e., default addr space, even
for indirect argument. This is because destructor of the indirect argument may
be called in the caller function, and address of the indirect argument may be
taken, in either case the indirect function argument is expected to be in default
addr space, not the alloca address space.

Therefore, the indirect function argument should be mapped to the temp var
casted to default address space. The caller will cast it to alloca addr space
when passing it to the callee. In the callee, the argument is also casted to the
default address space and used.

CallArg is refactored to facilitate this fix.

Differential Revision: https://reviews.llvm.org/D34367


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326946 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-07 21:45:40 +00:00
Rafael Espindola cba8d12198 Start setting dllimport/dllexport in setGVProperties.
This is the next step in setting dso_local for COFF.

The patches changes setGVProperties to first set dllimport/dllexport
and changes a few cases that were setting dllimport/dllexport
manually. With this a few more GVs are marked dso_local.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326397 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-01 00:35:47 +00:00
Saleem Abdulrasool bc95497330 CodeGen: use `llvm.used` for ObjC protocols
These symbols are supposed to be preserved even by the linker.  Use the
`llvm.used` to ensure that the symbols are not removed by DCE in the
linker.  This should be a no-op change on MachO since the symbols are
annotated as `no_dead_strip`.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@323247 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-23 19:35:51 +00:00
Eric Christopher 019ab6b7aa Remove unused addIfPresent function.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@322427 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-13 00:46:47 +00:00
Alex Lorenz 978d2c74ec [driver] Set the 'simulator' environment for Darwin when compiling for
iOS/tvOS/watchOS simulator

rdar://35135215

Differential Revision: https://reviews.llvm.org/D40682


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@320073 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-07 19:04:10 +00:00
Ahmed Bougacha 56e12b471f [CodeGen] Compute the objc EH vtable address point using inbounds GEP.
The object is provided by the objc runtime and is never visible in the
module itself, but even so, the address point we compute points into it,
and "+16" is guaranteed not to overflow.

This matches the c++ vtable IRGen.

Note that I'm not entirely convinced the 'i8*' type is correct here: at
the IR level, we're accessing memory that's outside the global object.
But we don't control the allocation, so it's not obviously wrong either.
But either way, this is only in a global initializer, so I don't think
it's going to be mucked with.  Filed PR35352 to discuss that.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@318545 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-17 19:46:47 +00:00
Volodymyr Sapsai 3e7ea4aed7 [CodeGen] Add support for IncompleteArrayType in Obj-C ivars.
Fixes an assertion failure when ivar is a struct containing incomplete
array. Also completes support for direct flexible array members.

rdar://problem/21054495

Reviewers: rjmccall, theraven

Reviewed By: rjmccall

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D38774



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316723 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-27 00:56:23 +00:00
Saleem Abdulrasool fcbf0e691c CodeGen: fix a case of incorrect checks for ivars
Ensure that we check the ivar containing decl for the DLL storage
attribute rather than the ivar itself as the dll storage is associated
to the interface decl not the ivar decl.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316545 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-25 03:58:15 +00:00
Zachary Turner 6c57331175 Revert "[ADT] Make Twine's copy constructor private."
This reverts commit 4e4ee1c507e2707bb3c208e1e1b6551c3015cbf5.

This is failing due to some code that isn't built on MSVC
so I didn't catch.  Not immediately obvious how to fix this
at first glance, so I'm reverting for now.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@315536 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-11 23:54:34 +00:00
Zachary Turner 29b9ec05e6 [ADT] Make Twine's copy constructor private.
There's a lot of misuse of Twine scattered around LLVM.  This
ranges in severity from benign (returning a Twine from a function
by value that is just a string literal) to pretty sketchy (storing
a Twine by value in a class).  While there are some uses for
copying Twines, most of the very compelling ones are confined
to the Twine class implementation itself, and other uses are
either dubious or easily worked around.

This patch makes Twine's copy constructor private, and fixes up
all callsites.

Differential Revision: https://reviews.llvm.org/D38767

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@315530 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-11 23:33:06 +00:00
Kuba Mracek fc0baba7f6 [objc] Don't require null-check and don't emit memset when result is ignored 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



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306837 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-30 16:28:15 +00:00
Saleem Abdulrasool 64b75be74b CodeGen: handle missed case of COMDAT handling
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306622 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-29 00:54:44 +00:00
Saleem Abdulrasool d5b2509387 CodeGen: make the type match the comment for a libcall
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305638 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-17 17:30:31 +00:00
Saleem Abdulrasool 4957517b0b CodeGen: fix section names for different file formats
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).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@304661 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-03 16:18:09 +00:00
Serge Guelton b0c092f298 Suppress all uses of LLVM_END_WITH_NULL. NFC.
Use variadic templates instead of relying on <cstdarg> + sentinel.

This enforces better type checking and makes code more readable.

Differential revision: https://reviews.llvm.org/D32550


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@302572 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-09 19:31:30 +00:00
Sanjoy Das e3c69705dc Adapt to LLVM's rename of WeakVH to WeakTrackingVH; NFC
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301815 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-01 17:08:00 +00:00
Sanjoy Das 808ced1c4d Revert "Update to LLVM's use of WeakTrackingVH; NFC"
This reverts commit r301427.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301430 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-26 16:37:51 +00:00
Sanjoy Das 2dfb9da1cc Update to LLVM's use of WeakTrackingVH; NFC
Summary: Depends on D32266

Reviewers: davide, dblaikie

Subscribers: mcrosier, llvm-commits

Differential Revision: https://reviews.llvm.org/D32270

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301427 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-26 16:22:36 +00:00
Reid Kleckner 9bd00f207c Update Clang for LLVM rename AttributeSet -> AttributeList
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@298394 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-21 16:57:30 +00:00
John McCall cf2a38c652 Promote ConstantInitBuilder to be a public CodeGen API; it's
a generally useful utility for other frontends.  NFC.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@296806 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-02 20:04:19 +00:00
John McCall e6a9e3fa57 Clean up CGObjCMac's APIs for deriving class references. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@288295 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-30 23:54:50 +00:00
John McCall 8b92834be5 Fix some layering violations where CGObjCMac's NSString emission was
performed at the CodeGenModule level.

Would be NFC except we now also use a different uniquing structure so
that we don't get spurious conflicts if you ask for both an NSString
and a CFString for the same content (which is possible with builtins).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@288287 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-30 23:15:55 +00:00
John McCall 1f955bd645 Prospective GCC build fix: the unelaborated form of this friend
declaration should find the right type, assuming it's supported
evenly across all our hosts.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@288231 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-30 04:18:19 +00:00
John McCall 5050adc78c Switch CGObjCMac to use ConstantInitBuilder. Whew.
Not strictly NFC because I did change the order of emission of
some global constants, but it shouldn't make any difference.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@288229 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-30 02:39:18 +00:00
John McCall 10abbcd4f8 getObjCEncodingForMethodDecl cannot fail. Simplify. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@288203 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-29 21:57:00 +00:00
John McCall a896e9a7d2 Refactor call emission to package the function pointer together with
abstract information about the callee.  NFC.

The goal here is to make it easier to recognize indirect calls and
trigger additional logic in certain cases.  That logic will come in
a later patch; in the meantime, I felt that this was a significant
improvement to the code.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285258 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-26 23:46:34 +00:00
Saleem Abdulrasool af04f931fc CodeGen: be more conservative about setting section
The section names currently are MachO specific.  Only set the section on the
variables if the file format is MachO.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285126 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-25 21:43:28 +00:00
Saleem Abdulrasool 0e776a3b8e CodeGen: mark protocols as common data
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285073 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-25 14:50:44 +00:00
Saleem Abdulrasool aab877938f CodeGen: remove incorrect temporary Twine
Twines should not be stack allocated.  This somehow managed to get past me.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285028 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-24 21:25:57 +00:00
Saleem Abdulrasool 7d8886efd2 CodeGen: centralise label construction for method lists
Move all the label construction for the various method list emission into
EmitMethodList.  Rather than have all the names be constructed in pieces in all
of the callers of EmitMethodList, have this occur in one site.  This also makes
the calls much easier to understand as we simplify identify the type of the
method list being emitted and the interface name for which it is being emitted.
NFC.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285023 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-24 20:47:58 +00:00
Justin Lebar a663b0aee8 Switch SmallSetVector to use DenseSet when it overflows its inline space.
Summary:
SetVector already used DenseSet, but SmallSetVector used std::set.  This
leads to surprising performance differences.  Moreover, it means that
the set of key types accepted by SetVector and SmallSetVector are
quite different!

In order to make this change, we had to convert some callsites that used
SmallSetVector<std::string, N> to use SmallSetVector<CachedHashString, N>
instead.

Reviewers: timshen

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D25648

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284887 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-21 21:45:01 +00:00
Saleem Abdulrasool f127b477d7 CodeGen: further merge cstring literal construction
Use the new CreateCStringLiteral in an additional site.  Now all the C string
literals are created in one function.  Furthermore, mark the additional literal
as an `unnamed_addr constant`.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@281997 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-20 18:38:54 +00:00
Saleem Abdulrasool f293c786ad CodeGen: mark ObjC cstring literals as unnamed_addr
These are all emitted into a section with a cstring_literal attribute.  The
attribute permits the linker to coalesce the string contents.  The address of
the strings are not important.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@281855 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-18 16:12:14 +00:00
Saleem Abdulrasool dba490c140 CodeGen: mark ObjC cstring literals as constant
These strings are constants, mark them as such.  This doesn't matter too much in
practice on MachO since the constants are placed into a special section and not
referred to directly.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@281854 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-18 16:12:04 +00:00
Saleem Abdulrasool c80f3af674 CodeGen: refactor the ObjC cstring literal creation
This refactors the cstring literal creation as mentioned in the couple of FIXMEs
littered in the various invocations to CreateMetadataVar.  This centralises the
definition of the literals, and will enable changing the literal creation to a
single site.  NFC.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@281798 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-16 23:41:13 +00:00
Saleem Abdulrasool 09183879d6 CodeGen: use pointer rather than reference in range loop
Address post-commit comments from Justin Bogner.  Explicitly indicate
that the dereferenced iterator provides a pointer rather than a
reference.  NFC.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@281730 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-16 14:24:26 +00:00
Saleem Abdulrasool 652fc62280 CodeGen: use some range-based for loops
Use range-based for loops to simplify the logic.  Add an explicit check for
MachO as the inline asm uses MachO specific directives.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@281261 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-12 21:15:23 +00:00
Saleem Abdulrasool 0aefc16423 CodeGen: honour dllstorage on ObjC types
Add support for ObjC types to respect the DLLImport/DLLExport storage
annotations.  This only effects COFF output.  This would allow usage with
clang/C2, but not with clang/LLVM due to hard coded section names.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275737 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-17 22:27:44 +00:00
Saleem Abdulrasool 1540342292 CodeGen: whitespace cleanup, StringRef usage in ObjC EH type construction
Clean up some formatting issues and use a bit more StringRef based operations
instead of SmallStrings.  NFC.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275735 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-17 22:27:38 +00:00
Saleem Abdulrasool da544ac278 CodeGen: use StringRefs more in ObjC class generation, NFC
Rather than building up a number of SmallString-s in order to construct a
std::string, use more StringRefs and construct the string once before use.  This
avoids unnecessary string constructions.  NFC.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275697 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-16 22:42:06 +00:00
Saleem Abdulrasool b29114bc67 CodeGen: simplify using a local variable, NFC
Add a couple of local variables for the class interface and the super class
interface.  This allows for the repeated access of the information to be cached
and makes the code simpler to understand.  NFC.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275696 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-16 22:42:04 +00:00
Saleem Abdulrasool 77938fad7d CodeGen: minor cleanup, NFC
Initialise more members in initializer lists.  Invert the condition that had
grown to be pretty confusing.  The `_objc_empty_vtable` is only used on macOS
<10.9.  This simplifies the code.  NFC.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275241 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-13 02:58:44 +00:00