aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaDeclObjC.cpp
AgeCommit message (Collapse)AuthorFilesLines
12 days[clang][ObjC][PAC] Add ptrauth protections to objective-c (#147899)Oliver Hunt1-0/+8
This PR introduces the use of pointer authentication to objective-c[++]. This includes: * __ptrauth qualifier support for ivars * protection of isa and super fields * protection of SEL typed ivars * protection of class_ro_t data * protection of methodlist pointers and content
2025-05-04[clang] Remove unused local variables (NFC) (#138453)Kazu Hirata1-1/+0
2025-05-02[clang][NFC] Convert `Sema::CorrectTypoKind` to scoped enumVlad Serebrennikov1-5/+5
2025-05-01[clang] Add scoped enum support to `StreamingDiagnostic` (#138089)Vlad Serebrennikov1-1/+1
This patch adds templated `operator<<` for diagnostics that pass scoped enums, saving people from `llvm::to_underlying()` clutter on the side of emitting the diagnostic. This eliminates 80 out of 220 usages of `llvm::to_underlying()` in Clang. I also backported `std::is_scoped_enum_v` from C++23.
2025-04-17Reland [clang] Unify `SourceLocation` and `IdentifierInfo*` pair-like data ↵yronglin1-16/+19
structures to `IdentifierLoc` (#136077) This PR reland https://github.com/llvm/llvm-project/pull/135808, fixed some missed changes in LLDB. I found this issue when I working on https://github.com/llvm/llvm-project/pull/107168. Currently we have many similiar data structures like: - std::pair<IdentifierInfo *, SourceLocation>. - Element type of ModuleIdPath. - IdentifierLocPair. - IdentifierLoc. This PR unify these data structures to IdentifierLoc, moved IdentifierLoc definition to SourceLocation.h, and deleted other similer data structures. --------- Signed-off-by: yronglin <yronglin777@gmail.com>
2025-04-16Revert "[clang] Unify `SourceLocation` and `IdentifierInfo*` pair-like data ↵Michael Buch1-19/+16
structures to `IdentifierLoc`" (#135974) Reverts llvm/llvm-project#135808 Example from the LLDB macOS CI: https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/24084/execution/node/54/log/?consoleFull ``` /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp:360:49: error: no viable conversion from 'std::pair<clang::IdentifierInfo *, clang::SourceLocation>' to 'clang::ModuleIdPath' (aka 'ArrayRef<IdentifierLoc>') clang::Module *top_level_module = DoGetModule(clang_path.front(), false); ^~~~~~~~~~~~~~~~~~ /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:41:40: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'std::pair<clang::IdentifierInfo *, clang::SourceLocation>' to 'const llvm::ArrayRef<clang::IdentifierLoc> &' for 1st argument class LLVM_GSL_POINTER [[nodiscard]] ArrayRef { ^ /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:41:40: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'std::pair<clang::IdentifierInfo *, clang::SourceLocation>' to 'llvm::ArrayRef<clang::IdentifierLoc> &&' for 1st argument /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:70:18: note: candidate constructor not viable: no known conversion from 'std::pair<clang::IdentifierInfo *, clang::SourceLocation>' to 'std::nullopt_t' for 1st argument /*implicit*/ ArrayRef(std::nullopt_t) {} ```
2025-04-16[clang] Unify `SourceLocation` and `IdentifierInfo*` pair-like data ↵yronglin1-16/+19
structures to `IdentifierLoc` (#135808) I found this issue when I working on https://github.com/llvm/llvm-project/pull/107168. Currently we have many similiar data structures like: - `std::pair<IdentifierInfo *, SourceLocation>`. - Element type of `ModuleIdPath`. - `IdentifierLocPair`. - `IdentifierLoc`. This PR unify these data structures to `IdentifierLoc`, moved `IdentifierLoc` definition to SourceLocation.h, and deleted other similer data structures. --------- Signed-off-by: yronglin <yronglin777@gmail.com>
2025-02-17[CodeGen][ObjC] Invalidate cached ObjC class layout information after ↵Akira Hatanaka1-0/+7
parsing ObjC class implementations if new ivars are added to the interface (#126591) The layout and the size of an ObjC interface can change after its corresponding implementation is parsed when synthesized ivars or ivars declared in categories are added to the interface's list of ivars. This can cause clang to mis-compile if the optimization that emits fixed offsets for ivars (see 923ddf65f4e21ec67018cf56e823895de18d83bc) uses an ObjC class layout that is outdated and no longer reflects the current state of the class. For example, when compiling `constant-non-fragile-ivar-offset.m`, clang emits 20 instead of 24 as the offset for `IntermediateClass2Property` as the class layout for `SuperClass2`, which is created when the implementation of IntermediateClass3 is parsed, is outdated when the implementation of `IntermediateClass2` is parsed. This commit invalidates the stale layout information of the class and its subclasses if new ivars are added to the interface. With this change, we can also stop using ObjC implementation decls as the key to retrieve ObjC class layouts information as the layout retrieved using the ObjC interface as the key will always be up to date. rdar://139531391
2025-02-03[Sema] Migrate away from PointerUnion::dyn_cast (NFC) (#125457)Kazu Hirata1-1/+1
Note that PointerUnion::dyn_cast has been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with // isa<T>, cast<T> and the llvm::dyn_cast<T> Literal migration would result in dyn_cast_if_present (see the definition of PointerUnion::dyn_cast), but this patch uses dyn_cast because we expect typeDecl to be nonnull. Note that getObjCInterfaceType starts out dereferencing Decl.
2025-01-11Reapply "[clang] Avoid re-evaluating field bitwidth" (#122289)Timm Baeder1-2/+1
2025-01-08Revert "[clang] Avoid re-evaluating field bitwidth (#117732)"Timm Bäder1-1/+2
This reverts commit 81fc3add1e627c23b7270fe2739cdacc09063e54. This breaks some LLDB tests, e.g. SymbolFile/DWARF/x86/no_unique_address-with-bitfields.cpp: lldb: ../llvm-project/clang/lib/AST/Decl.cpp:4604: unsigned int clang::FieldDecl::getBitWidthValue() const: Assertion `isa<ConstantExpr>(getBitWidth())' failed.
2025-01-08[clang] Avoid re-evaluating field bitwidth (#117732)Timm Baeder1-2/+1
Save the bitwidth value as a `ConstantExpr` with the value set. Remove the `ASTContext` parameter from `getBitWidthValue()`, so the latter simply returns the value from the `ConstantExpr` instead of constant-evaluating the bitwidth expression every time it is called.
2024-11-27[Sema] Migrate away from PointerUnion::{is,get} (NFC) (#117498)Kazu Hirata1-1/+1
Note that PointerUnion::{is,get} have been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with // isa<T>, cast<T> and the llvm::dyn_cast<T> I'm not touching PointerUnion::dyn_cast for now because it's a bit complicated; we could blindly migrate it to dyn_cast_if_present, but we should probably use dyn_cast when the operand is known to be non-null.
2024-11-16[Sema] Remove unused includes (NFC) (#116461)Kazu Hirata1-1/+0
Identified with misc-include-cleaner.
2024-11-15[Clang] [NFC] Refactor AST visitors in Sema and the static analyser to use ↵Sirraide1-5/+4
DynamicRecursiveASTVisitor (#115144) This pr refactors all recursive AST visitors in `Sema`, `Analyze`, and `StaticAnalysis` to inherit from DRAV instead. This is over half of the visitors that inherit from RAV directly. See also #115132, #110040, #93462 LLVM Compile-Time Tracker link for this branch: https://llvm-compile-time-tracker.com/compare.php?from=5adb5c05a2e9f31385fbba8b0436cbc07d91a44d&to=b58e589a86c06ba28d4d90613864d10be29aa5ba&stat=instructions%3Au
2024-10-31[clang/AST] Make it possible to use SwiftAttr in type context (#108631)Pavel Yaskevich1-3/+1
Swift ClangImporter now supports concurrency annotations on imported declarations and their parameters/results, to make it possible to use imported APIs in Swift safely there has to be a way to annotate individual parameters and result types with relevant attributes that indicate that e.g. a block is called on a particular actor or it accepts a `Sendable` parameter. To faciliate that `SwiftAttr` is switched from `InheritableAttr` which is a declaration attribute to `DeclOrTypeAttr`. To support this attribute in type context we need access to its "Attribute" argument which requires `AttributedType` to be extended to include `Attr *` when available instead of just `attr::Kind` otherwise it won't be possible to determine what attribute should be imported.
2024-10-30[ObjC] Insert method parameters in scope as they are parsed (#113745)apple-fcloutier1-54/+58
Before this change, ParseObjc would call the closing `MaybeParseAttributes` before it had created Objective-C `ParmVarDecl` objects (and associated name lookup entries), meaning that you could not reference Objective-C method parameters in `__attribute__((diagnose_if))`. This change moves the creation of the `ParmVarDecl` objects ahead of calling `Sema::ActOnMethodDeclaration` so that `MaybeParseAttributes` can find them. This is already how it works for C parameters hanging off of the selector. This change alone is insufficient to enable `diagnose_if` for Objective-C methods and effectively is NFC. There will be a follow-up PR for diagnose_if. This change is still useful for any other work that may need attributes to reference Objective-C parameters. rdar://138596211
2024-10-24[clang] Use {} instead of std::nullopt to initialize empty ArrayRef (#109399)Jay Foad1-3/+2
Follow up to #109133.
2024-09-20[Sema] Declare GlobalMethodPool with using (NFC) (#109437)Kazu Hirata1-1/+1
GlobalMethodPool is a wrapper around DenseMap that does not add anything except: using Lists = std::pair<ObjCMethodList, ObjCMethodList>; This patch removes the wrapper and switches to an alias with "using". In ReadMethodPool in ASTReader.cpp, we can simplify: insert(std::make_pair(Sel, SemaObjC::GlobalMethodPool::Lists())) to: try_emplace(Sel) But then try_emplace(Sel).first->second is the same as operator[], so this patch simplifies the rest of the function.
2024-09-20[Sema] Avoid repeated hash lookups (NFC) (#109375)Kazu Hirata1-7/+2
GlobalMethodPool, the type of MethodPool, is a type wrapping DenseMap and exposes only a subset of the DenseMap methods. This patch adds operator[] to GlobalMethodPool so that we can avoid repeated hash lookups. I don't bother using references or rvalue references in operator[] because Selector, the key type, is small and trivially copyable. Note that Selector is a class that wraps a PointerUnion.
2024-05-30[clang][NFC] Move `PDiag` into `SemaBase` (#93849)Vlad Serebrennikov1-21/+17
This patch moves `PDiag` into `SemaBase`, making it readily available everywhere across `Sema` without `SemaRef`, like the regular `Diag`.
2024-05-13[clang] Introduce `SemaObjC` (#89086)Vlad Serebrennikov1-569/+875
This is continuation of efforts to split `Sema` up, following the example of OpenMP, OpenACC, etc. Context can be found in https://github.com/llvm/llvm-project/pull/82217 and https://github.com/llvm/llvm-project/pull/84184. I split formatting changes into a separate commit to help reviewing the actual changes.
2024-04-23[clang] Set correct FPOptions if attribute 'optnone' presents (#85605)Serge Pavlov1-0/+4
Attribute `optnone` must turn off all optimizations including fast-math ones. Actually AST nodes in the 'optnone' function still had fast-math flags. This change implements fixing FP options before function body is parsed.
2024-04-11[NFC][Clang] Improve const correctness for IdentifierInfo (#79365)Bill Wendling1-12/+11
The IdentifierInfo isn't typically modified. Use 'const' wherever possible.
2024-03-01[clang][sema] NFC: Stylistic changesJan Svoboda1-2/+6
2024-02-26[APINotes] Upstream Sema logic to apply API Notes to declsEgor Zhdan1-0/+4
This upstreams more of the Clang API Notes functionality that is currently implemented in the Apple fork: https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes This was extracted from a larger PR: https://github.com/llvm/llvm-project/pull/73017
2024-01-17[Clang][Sema][NFC] Remove unused Scope* parameter from ↵Krystian Stasiowski1-2/+2
Sema::GetTypeForDeclarator and Sema::ActOnTypeName (#78325) Split from #78274
2023-12-13[clang] Use StringRef::{starts,ends}_with (NFC) (#75149)Kazu Hirata1-1/+1
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-11-03[clang][NFC] Refactor `TagTypeKind` (#71160)Vlad Serebrennikov1-1/+1
This patch converts TagTypeKind into scoped enum. Among other benefits, this allows us to forward-declare it where necessary.
2023-11-01[clang][NFC] Refactor `ObjCMethodDecl::ImplementationControl`Vlad Serebrennikov1-36/+36
This patch moves `ObjCMethodDecl::ImplementationControl` to a DeclBase.h so that it's complete at the point where corresponsing bit-field is declared. This patch also converts it to a scoped enum `clang::ObjCImplementationControl`.
2023-01-20[modules] Allow parsing a duplicate Obj-C interface if a previous one comes ↵Volodymyr Sapsai1-6/+14
from a hidden [sub]module. Instead of emitting a redefinition error, check that definitions are equivalent and allow such scenario. A few non-obvious implementation details: * to avoid multiple definitions in the redeclaration chain we just drop the new definition after checking for equivalence; * for checking definition equivalence use ODR hash instead of ASTStructuralEquivalence because it avoids excessive recursive deserialization. Though after detecting a mismatch we do deserialize multiple entities to provide a better error message. rdar://82908223 Differential Revision: https://reviews.llvm.org/D124286
2022-12-16[clang][dataflow] Remove unused argument in getNullabilityDani Ferreira Franco Moura1-25/+19
This change will allow users to call getNullability() without providing an ASTContext. Reviewed By: gribozavr2 Differential Revision: https://reviews.llvm.org/D140104
2022-11-24[modules] Fix marking `ObjCMethodDecl::isOverriding` when there are no ↵Volodymyr Sapsai1-3/+7
overrides. Incorrect `isOverriding` flag triggers the assertion `!Overridden.empty()` in `ObjCMethodDecl::getOverriddenMethods` when a method is marked as overriding but we cannot find any overrides. When a method is declared in a category and defined in implementation, we don't treat it as an override because it is the same method with a separate declaration and a definition. But with modules we can find a method declaration both in a modular category and a non-modular category with different memory addresses. Thus we erroneously conclude the method is overriding. Fix by comparing canonical declarations that are the same for equal entities coming from different modules. rdar://92845511 Differential Revision: https://reviews.llvm.org/D138630
2022-11-17[ODRHash] Detect duplicate `ObjCProtocolDecl` ODR mismatches during parsing.Volodymyr Sapsai1-7/+13
When during parsing we encountered a duplicate `ObjCProtocolDecl`, we were always emitting an error. With this change we accept * when a previous `ObjCProtocolDecl` is in a hidden [sub]module; * parsed `ObjCProtocolDecl` is the same as the previous one. And in case of mismatches we provide more detailed error messages. rdar://93069080 Differential Revision: https://reviews.llvm.org/D130327
2022-09-03[clang] Qualify auto in range-based for loops (NFC)Kazu Hirata1-6/+6
2022-08-01Fixed a number of typosGabriel Ravier1-1/+1
I went over the output of the following mess of a command: (ulimit -m 2000000; ulimit -v 2000000; git ls-files -z | parallel --xargs -0 cat | aspell list --mode=none --ignore-case | grep -E '^[A-Za-z][a-z]*$' | sort | uniq -c | sort -n | grep -vE '.{25}' | aspell pipe -W3 | grep : | cut -d' ' -f2 | less) and proceeded to spend a few days looking at it to find probable typos and fixed a few hundred of them in all of the llvm project (note, the ones I found are not anywhere near all of them, but it seems like a good start). Differential Revision: https://reviews.llvm.org/D130827
2022-06-20[clang] Don't use Optional::hasValue (NFC)Kazu Hirata1-1/+1
2022-06-15[clang] Reject non-declaration C++11 attributes on declarationsMartin Boehme1-1/+1
For backwards compatiblity, we emit only a warning instead of an error if the attribute is one of the existing type attributes that we have historically allowed to "slide" to the `DeclSpec` just as if it had been specified in GNU syntax. (We will call these "legacy type attributes" below.) The high-level changes that achieve this are: - We introduce a new field `Declarator::DeclarationAttrs` (with appropriate accessors) to store C++11 attributes occurring in the attribute-specifier-seq at the beginning of a simple-declaration (and other similar declarations). Previously, these attributes were placed on the `DeclSpec`, which made it impossible to reconstruct later on whether the attributes had in fact been placed on the decl-specifier-seq or ahead of the declaration. - In the parser, we propgate declaration attributes and decl-specifier-seq attributes separately until we can place them in `Declarator::DeclarationAttrs` or `DeclSpec::Attrs`, respectively. - In `ProcessDeclAttributes()`, in addition to processing declarator attributes, we now also process the attributes from `Declarator::DeclarationAttrs` (except if they are legacy type attributes). - In `ConvertDeclSpecToType()`, in addition to processing `DeclSpec` attributes, we also process any legacy type attributes that occur in `Declarator::DeclarationAttrs` (and emit a warning). - We make `ProcessDeclAttribute` emit an error if it sees any non-declaration attributes in C++11 syntax, except in the following cases: - If it is being called for attributes on a `DeclSpec` or `DeclaratorChunk` - If the attribute is a legacy type attribute (in which case we only emit a warning) The standard justifies treating attributes at the beginning of a simple-declaration and attributes after a declarator-id the same. Here are some relevant parts of the standard: - The attribute-specifier-seq at the beginning of a simple-declaration "appertains to each of the entities declared by the declarators of the init-declarator-list" (https://eel.is/c++draft/dcl.dcl#dcl.pre-3) - "In the declaration for an entity, attributes appertaining to that entity can appear at the start of the declaration and after the declarator-id for that declaration." (https://eel.is/c++draft/dcl.dcl#dcl.pre-note-2) - "The optional attribute-specifier-seq following a declarator-id appertains to the entity that is declared." (https://eel.is/c++draft/dcl.dcl#dcl.meaning.general-1) The standard contains similar wording to that for a simple-declaration in other similar types of declarations, for example: - "The optional attribute-specifier-seq in a parameter-declaration appertains to the parameter." (https://eel.is/c++draft/dcl.fct#3) - "The optional attribute-specifier-seq in an exception-declaration appertains to the parameter of the catch clause" (https://eel.is/c++draft/except.pre#1) The new behavior is tested both on the newly added type attribute `annotate_type`, for which we emit errors, and for the legacy type attribute `address_space` (chosen somewhat randomly from the various legacy type attributes), for which we emit warnings. Depends On D111548 Reviewed By: aaron.ballman, rsmith Differential Revision: https://reviews.llvm.org/D126061
2022-05-05[clang][NFC] In parts of Objective-C Sema use Obj-C-specific types instead ↵Volodymyr Sapsai1-22/+27
of `Decl`. Differential Revision: https://reviews.llvm.org/D124285
2022-01-06Reland "[clang][ObjC] Add fix it for missing methods in impl"David Goldman1-26/+28
This reverts commit 37be74885946f18dbeb70343ad659924c61d2549/ relands https://reviews.llvm.org/D116417 now that the internal issue has been fixed.
2022-01-04Revert "[clang][ObjC] Add fix it for missing methods in impl"Rumeet Dhindsa1-28/+26
This reverts commit dd72ae3dcc6895f95e1203b40aabcb069c76a0ab. Notified the author of the internal failure and author suggested to revert it for now.
2022-01-04[clang][ObjC] Add fix it for missing methods in implDavid Goldman1-26/+28
We suggest inserting the method with an empty body at the end of the implementation decl. Differential Revision: https://reviews.llvm.org/D116417
2021-11-14[clang] Use isa instead of dyn_cast (NFC)Kazu Hirata1-1/+1
2021-10-30Use {DenseSet,SetVector,SmallPtrSet}::contains (NFC)Kazu Hirata1-2/+1
2021-09-20[clang] Fix a few comment more typos to cycle botsNico Weber1-2/+2
2021-09-16[clang][NFC] refactor GlobalMethodPool to encapsulate its mapRichard Howell1-3/+5
This refactor changes the GlobalMethodPool to a class that contains the DenseMap of methods. This is to allow for the addition of a separate DenseSet in a follow-up diff that will handle method de-duplication when inserting methods into the global method pool. Changes: - the `GlobalMethods` pair becomes `GlobalMethodPool::Lists` - the `GlobalMethodPool` becomes a class containing the `DenseMap` of methods - pass through methods are added to maintain most of the existing code without changing `MethodPool` -> `MethodPool.Methods` everywhere Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D109898
2021-04-06[ObjC] Add a command line flag that disables recognition of objc_direct for ↵Erik Pilkington1-5/+10
testability Programmers would like to be able to test direct methods by calling them from a different linkage unit or mocking them, both of which are impossible. This patch adds a flag that effectively disables the attribute, which will fix this when enabled in testable builds. rdar://71190891 Differential revision: https://reviews.llvm.org/D95845
2021-01-04Revert "[NFC, Refactor] Modernize StorageClass from Specifiers.h to a scoped ↵Thorsten Schütt1-5/+5
enum (II)" This reverts commit efc82c4ad2bcb256a4f4c20238d08cd3afba4d2d.
2021-01-04[NFC, Refactor] Modernize StorageClass from Specifiers.h to a scoped enum (II)Thorsten Schütt1-5/+5
Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D93765
2020-12-04[objc] diagnose protocol conformance in categories with direct membersAlex Lorenz1-0/+51
in their corresponding class interfaces Categories that add protocol conformances to classes with direct members should prohibit protocol conformances when the methods/properties that the protocol expects are actually declared as 'direct' in the class. Differential Revision: https://reviews.llvm.org/D92602