aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaDecl.cpp
AgeCommit message (Collapse)AuthorFilesLines
2024-06-11[clang] Fix a few comment typos to cycle botsNico Weber1-13/+13
2024-06-05Fix clang reject valid C++ code after d999ce0302f06d250f6d496b56a5a5f (#94471)Haojian Wu1-1/+2
The incremental processing mode doesn't seem to work well for C++, see the https://github.com/llvm/llvm-project/pull/89804#issuecomment-2149840711 for details.
2024-06-05[clang] Split up `SemaDeclAttr.cpp` (#93966)Vlad Serebrennikov1-1/+2
This patch moves language- and target-specific functions out of `SemaDeclAttr.cpp`. As a consequence, `SemaAVR`, `SemaM68k`, `SemaMSP430`, `SemaOpenCL`, `SemaSwift` were created (but they are not the only languages and targets affected). Notable things are that `Sema.h` actually grew a bit, because of templated helpers that rely on `Sema` that I had to make available from outside of `SemaDeclAttr.cpp`. I also had to left CUDA-related in `SemaDeclAttr.cpp`, because it looks like HIP is building up on top of CUDA attributes. This is a follow-up to #93179 and continuation of efforts to split `Sema` up. Additional context can be found in #84184 and #92682.
2024-06-04Reland "[clang-repl] Extend the C support. (#89804)"Vassil Vassilev1-3/+7
Original commit message:" [clang-repl] Extend the C support. (#89804) The IdResolver chain is the main way for C to implement lookup rules. Every new partial translation unit caused clang to exit the top-most scope which in turn cleaned up the IdResolver chain. That was not an issue for C++ because its lookup is implemented on the level of declaration contexts. This patch keeps the IdResolver chain across partial translation units maintaining proper C-style lookup infrastructure. " It was reverted in dfdf1c5fe45a82b9c578306f3d7627fd251d63f8 because it broke the bots of lldb. This failure was subtle to debug but the current model does not work well with ObjectiveC support in lldb. This patch does cleans up the partial translation units in ObjectiveC. In future if we want to support ObjectiveC we need to understand what exactly lldb is doing when recovering from errors...
2024-06-04[NFC] [AST] Introduce Decl::isInAnotherModuleUnit and ↵Chuanqi Xu1-1/+1
Decl::shouldEmitInExternalSource Motivated by the review process in https://github.com/llvm/llvm-project/pull/75912. This can also help to simplify the code slightly.
2024-05-30[clang] Introduce target-specific `Sema` components (#93179)Vlad Serebrennikov1-6/+8
This patch introduces `SemaAMDGPU`, `SemaARM`, `SemaBPF`, `SemaHexagon`, `SemaLoongArch`, `SemaMIPS`, `SemaNVPTX`, `SemaPPC`, `SemaSystemZ`, `SemaWasm`. This continues previous efforts to split Sema up. Additional context can be found in #84184 and #92682. I decided to bundle target-specific components together because of their low impact on `Sema`. That said, their impact on `SemaChecking.cpp` is far from low, and I consider it a success. Somewhat accidentally, I also moved Wasm- and AMDGPU-specific function from `SemaDeclAttr.cpp`, because they were exposed in `Sema`. That went well, and I consider it a success, too. I'd like to move the rest of static target-specific functions out of `SemaDeclAttr.cpp` like we're doing with built-ins in `SemaChecking.cpp` .
2024-05-29[clang] Preserve Qualifiers and type sugar in TemplateNames (#93433)Matheus Izvekov1-8/+7
This patch improves the preservation of qualifiers and loss of type sugar in TemplateNames. This problem is analogous to https://reviews.llvm.org/D112374 and this patch takes a very similar approach to that patch, except the impact here is much lesser. When a TemplateName was written bare, without qualifications, we wouldn't produce a QualifiedTemplate which could be used to disambiguate it from a Canonical TemplateName. This had effects in the TemplateName printer, which had workarounds to deal with this, and wouldn't print the TemplateName as-written in most situations. There are also some related fixes to help preserve this type sugar along the way into diagnostics, so that this patch can be properly tested. - Fix dropping the template keyword. - Fix type deduction to preserve sugar in TST TemplateNames.
2024-05-23[clang][FMV] Allow declaration of function versions in namespaces. (#93044)Alexandros Lamprineas1-2/+2
Fixes the following bug: namespace Name { int __attribute((target_version("default"))) foo() { return 0; } } namespace Name { int __attribute((target_version("sve"))) foo() { return 1; } } int bar() { return Name::foo(); } error: redefinition of 'foo' int __attribute((target_version("sve"))) foo() { return 1; } note: previous definition is here int __attribute((target_version("default"))) foo() { return 0; } While fixing this I also found that in the absence of default version declaration, the one we implicitly create has incorrect mangling if we are in a namespace: namespace OtherName { int __attribute((target_version("sve"))) foo() { return 2; } } int baz() { return OtherName::foo(); } In this example instead of creating a declaration for the symbol @_ZN9OtherName3fooEv.default we are creating one for the symbol @_Z3foov.default (the namespace mangling prefix is omitted). This has now been fixed.
2024-05-22[clang] Introduce `SemaRISCV` (#92682)Vlad Serebrennikov1-2/+3
This patch moves `Sema` functions that are specific for RISC-V into the new `SemaRISCV` class. This continues previous efforts to split `Sema` up. Additional context can be found in https://github.com/llvm/llvm-project/pull/84184. This PR is somewhat different from previous PRs on this topic: 1. Splitting out target-specific functions wasn't previously discussed. It felt quite natural to do, though. 2. I had to make some static function in `SemaChecking.cpp` member functions of `Sema` in order to use them in `SemaRISCV`. 3. I dropped "RISCV" from identifiers, but decided to leave "RVV" (RISC-V "V" vector extensions) intact. I think it's an idiomatic abbreviation at this point, but I'm open to input from contributors in that area. 4. I repurposed `SemaRISCVVectorLookup.cpp` for `SemaRISCV`. I think this was a successful experiment, which both helps the goal of splitting `Sema` up, and shows a way to approach `SemaChecking.cpp`, which I wasn't sure how to approach before. As we move more target-specific function out of there, we'll gradually make the checking "framework" inside `SemaChecking.cpp` public, which is currently a whole bunch of static functions. This would enable us to move more functions outside of `SemaChecking.cpp`.
2024-05-21Revert "[clang-repl] Extend the C support. (#89804)"Jason Molenda1-7/+3
This reverts commit 253c28fa829cee0104c2fc59ed1a958980b5138c. This commit is causing failures on the lldb CI bots, e.g. https://ci.swift.org/view/all/job/llvm.org/view/LLDB/job/as-lldb-cmake/4307/ On my local macOS desktop build, ``` bin/lldb-dotest -p TestImportBuiltinFileID.py Assertion failed: (D->getLexicalDeclContext() == this && "Decl inserted into wrong lexical context"), function addHiddenDecl, file DeclBase.cpp, line 1692. 6 libsystem_c.dylib 0x0000000185f0b8d0 abort + 128 7 libsystem_c.dylib 0x0000000185f0abc8 err + 0 8 liblldb.19.0.0git.dylib 0x00000001311e5800 clang::DeclContext::addHiddenDecl(clang::Decl*) + 120 9 liblldb.19.0.0git.dylib 0x00000001311e5978 clang::DeclContext::addDecl(clang::Decl*) + 32 10 liblldb.19.0.0git.dylib 0x000000012f617b48 clang::Sema::ActOnStartTopLevelStmtDecl(clang::Scope*) + 64 11 liblldb.19.0.0git.dylib 0x000000012eaf76c8 clang::Parser::ParseTopLevelStmtDecl() + 208 12 liblldb.19.0.0git.dylib 0x000000012ec051fc clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) + 3412 13 liblldb.19.0.0git.dylib 0x000000012ec03274 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) + 2020 14 liblldb.19.0.0git.dylib 0x000000012eaca860 clang::ParseAST(clang::Sema&, bool, bool) + 604 15 liblldb.19.0.0git.dylib 0x000000012e8554c0 clang::ASTFrontendAction::ExecuteAction() + 308 16 liblldb.19.0.0git.dylib 0x000000012e854c78 clang::FrontendAction::Execute() + 124 17 liblldb.19.0.0git.dylib 0x000000012e76dcfc clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 984 18 liblldb.19.0.0git.dylib 0x000000012e784500 compileModuleImpl(clang::CompilerInstance&, clang::SourceLocation, llvm::StringRef, clang::FrontendInputFile, llvm::StringRef, llvm::StringRef, llvm::function_ref<void (clang::CompilerInstance&)>, llvm::function_ref<void (clang::CompilerInstance&)>)::$_1::operator()() const + 52 ``` Reverting until Vassil has a chance to look int oit.
2024-05-22[clang][NFC] Refactor `Sema::TagUseKind` (#92689)Vlad Serebrennikov1-43/+48
This patch makes `TagUseKind` a scoped enumeration, and moves it outside of `Sema` class, making it eligible for forward declaring.
2024-05-21[clang-repl] Extend the C support. (#89804)Vassil Vassilev1-3/+7
The IdResolver chain is the main way for C to implement lookup rules. Every new partial translation unit caused clang to exit the top-most scope which in turn cleaned up the IdResolver chain. That was not an issue for C++ because its lookup is implemented on the level of declaration contexts. This patch keeps the IdResolver chain across partial translation units maintaining proper C-style lookup infrastructure.
2024-05-20[Clang][Sema] Fix crash when diagnosing near-match for 'constexpr' ↵Krystian Stasiowski1-10/+11
redeclaration in C++11 (#92452) Clang crashes when diagnosing the following invalid redeclaration in C++11: ``` struct A { void f(); }; constexpr void A::f() { } // crash here ``` This happens because `DiagnoseInvalidRedeclaration` tries to create a fix-it to remove `const` from the out-of-line declaration of `f`, but there is no `SourceLocation` for the `const` qualifier (it's implicitly `const` due to `constexpr`) and an assert in `FunctionTypeInfo::getConstQualifierLoc` fails. This patch changes `DiagnoseInvalidRedeclaration` to only suggest the removal of the `const` qualifier when it was explicitly specified in the _cv-qualifier-seq_ of the declaration.
2024-05-19[Clang][HLSL] Add environment parameter to availability attribute (#89809)Helena Kotas1-1/+1
Add `environment` parameter to Clang availability attribute. The allowed values for this parameter are a subset of values allowed in the `llvm::Triple` environment component. If the `environment` parameters is present, the declared availability attribute applies only to targets with the same platform and environment. This new parameter will be initially used for annotating HLSL functions for the `shadermodel` platform because in HLSL built-in function availability can depend not just on the shader model version (mapped to `llvm::Triple::OSType`) but also on the target shader stage (mapped to `llvm::Triple::EnvironmentType`). See example in #89802 and microsoft/hlsl-specs#204 for more details. The environment parameter is currently supported only for HLSL. Fixes #89802
2024-05-17[clang][NFC] Add `const` qualifier in `Sema::isIncompatibleTypedef`Vlad Serebrennikov1-5/+5
2024-05-17[Clang][AArch64] Require SVE or SSVE for scalable types. (#91356)Sander de Smalen1-5/+14
Scalable types are only available when: * The function is compiled with +sve * The function is compiled with +sme and the function is executed in Streaming-SVE mode.
2024-05-17[clang] Implement CWG2428 "Deprecating a concept" (#92295)Vlad Serebrennikov1-0/+5
This patch allows attributes to be attached to C++20 concepts, implementing [CWG2428](https://cplusplus.github.io/CWG/issues/2428.html).
2024-05-13[clang] Introduce `SemaObjC` (#89086)Vlad Serebrennikov1-278/+14
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-05-11[clang] Use StringRef::operator== instead of StringRef::equals (NFC) (#91844)Kazu Hirata1-4/+4
I'm planning to remove StringRef::equals in favor of StringRef::operator==. - StringRef::operator==/!= outnumber StringRef::equals by a factor of 24 under clang/ in terms of their usage. - The elimination of StringRef::equals brings StringRef closer to std::string_view, which has operator== but not equals. - S == "foo" is more readable than S.equals("foo"), especially for !Long.Expression.equals("str") vs Long.Expression != "str".
2024-05-07[clang] Don't preserve the typo expr in the recovery expr for invalid ↵Haojian Wu1-2/+5
VarDecls (#90948) With the commit d5308949cf884d8e4b971d51a8b4f73584c4adec, we now preserve the initializer for invalid decls with the recovery-expr. However there is a chance that the original init expr is a typo-expr, we should not preserve it in the final AST, as typo-expr is an internal AST node. We should use the one after the typo correction. This is spotted by a clangd hover crash on the testcase.
2024-05-02[clang] fix(85447): clang 18.1.0 crashes in ↵Oleksandr T1-0/+3
clang::ASTContext::getTypeInfoImpl (#89850) Fixes #85447 --- This PR resolves a crash in `ActOnUninitializedDecl` due to an oversight in updating the `isInvalidDecl` state before invocation. The crash occurs due to a missing invocation of `setInvalidDecl()` for an invalid `Anon` declaration. To address this issue, the `setInvalidDecl()` method is now properly invoked to mark the `Anon` declaration as invalid before running `ActOnUninitializedDecl()`.
2024-04-30Reapply "[Clang][Sema] Diagnose class member access expressions naming ↵Krystian Stasiowski1-3/+4
non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (#84050)" (#90152) Reapplies #84050, addressing a bug which cases a crash when an expression with the type of the current instantiation is used as the _postfix-expression_ in a class member access expression (arrow form).
2024-04-28[Clang] Implement C++26 Attributes for Structured Bindings (P0609R3) (#89906)cor3ntin1-1/+1
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p0609r3.pdf We support this feature in all language mode. maybe_unused applied to a binding makes the whole declaration unused.
2024-04-26Revert "[Clang][Sema] Diagnose class member access expressions naming ↵Pranav Kant1-4/+3
non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (#84050)" This reverts commit a8fd0d029dca7d17eee72d0445223c2fe1ee7758.
2024-04-25[Clang][Sema] Diagnose class member access expressions naming non-existent ↵Krystian Stasiowski1-3/+4
members of the current instantiation prior to instantiation in the absence of dependent base classes (#84050) Consider the following: ```cpp template<typename T> struct A { auto f() { return this->x; } }; ``` Although `A` has no dependent base classes and the lookup context for `x` is the current instantiation, we currently do not diagnose the absence of a member `x` until `A<T>::f` is instantiated. This patch moves the point of diagnosis for such expressions to occur at the point of definition (i.e. prior to instantiation).
2024-04-24[clang][Sema] Preserve the initializer of invalid VarDecls (#88645)Nathan Ridge1-6/+17
Fixes https://github.com/clangd/clangd/issues/1821
2024-04-24[Clang][AArch64] Extend diagnostics when warning non/streaming about vector ↵Dinar Temirbulatov1-3/+7
size difference (#88380) Add separate messages about passing arguments or returning parameters with scalable types. --------- Co-authored-by: Sander de Smalen <sander.desmalen@arm.com>
2024-04-23[clang] Set correct FPOptions if attribute 'optnone' presents (#85605)Serge Pavlov1-0/+19
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-22Reapply "[Clang][Sema] Fix crash when 'this' is used in a dependent class ↵Krystian Stasiowski1-2/+2
scope function template specialization that instantiates to a static member function (#87541, #88311)" (#88731) Reapplies #87541 and #88311 (again) addressing the bug which caused expressions naming overload sets to be incorrectly rebuilt, as well as the bug which caused base class members to always be treated as overload sets. The primary change since #88311 is `UnresolvedLookupExpr::Create` is called directly in `BuildPossibleImplicitMemberExpr` with `KnownDependent` as `true` (which causes the expression type to be set to `ASTContext::DependentTy`). This ensures that any further semantic analysis involving the type of the potentially implicit class member access expression is deferred until instantiation.
2024-04-19Reapply "[Clang][AArch64] Warn when calling non/streaming about vector size ↵Dinar Temirbulatov1-1/+11
difference (#79842)" This reverts commit 950bb097e11d6ee26533c00519c62df994322228
2024-04-18[clang][NFC] Fix FieldDecl::isUnnamedBitfield() capitalization (#89048)Timm Baeder1-1/+1
We always capitalize bitfield as "BitField".
2024-04-18[Clang][Sema] set declaration invalid earlier to prevent crash in ↵Qizhi Hu1-0/+7
calculating record layout (#87173) Try to fix https://github.com/llvm/llvm-project/issues/75221 This crash caused by calculating record layout which contains a field declaration with dependent type. Make it invalid before it is a complete definition to prevent this crash. Define a new scope type to record this type alias and set the record declaration invalid when it is defined in a type alias template. Co-authored-by: huqizhi <836744285@qq.com>
2024-04-17Revert "[Clang][AArch64] Warn when calling non/streaming about vector size ↵Dinar Temirbulatov1-11/+1
difference (#79842)" This reverts commit 4e85e1ffcaf161736e27a24c291c1177be865976
2024-04-17[clang][NFC] Refactor `Sema::RedeclarationKind`Vlad Serebrennikov1-10/+14
This patch converts the enum into scoped enum, and moves it into its own header for the time being. It's definition is needed in `Sema.h`, and is going to be needed in upcoming `SemaObjC.h`. `Lookup.h` can't hold it, because it includes `Sema.h`.
2024-04-17[clang][NFC] Move `Sema::SkipBodyInfo` into namespace scopeVlad Serebrennikov1-2/+2
This makes it forward-declarable, and needed from splitting `Sema` up.
2024-04-16[AST][RecoveryExpr] Fix a crash on c89/c90 invalid InitListExpr (#88008) ↵Ding Fei1-17/+11
(#88014) Use refactored `CheckForConstantInitializer()` to skip checking expr with error. --------- Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2024-04-16[clang] Introduce `SemaOpenMP` (#88642)Vlad Serebrennikov1-14/+18
This patch moves OpenMP-related entities out of `Sema` to a newly created `SemaOpenMP` class. This is a part of the effort to split `Sema` up, and follows the recent example of CUDA, OpenACC, SYCL, HLSL. Additional context can be found in https://github.com/llvm/llvm-project/pull/82217, https://github.com/llvm/llvm-project/pull/84184, https://github.com/llvm/llvm-project/pull/87634.
2024-04-14[Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (#86526)Sirraide1-1/+11
This implements support for the `= delete("message")` syntax that was only just added to C++26 ([P2573R2](https://isocpp.org/files/papers/P2573R2.html#proposal-scope)).
2024-04-13[clang] Introduce `SemaCUDA` (#88559)Vlad Serebrennikov1-9/+10
This patch moves CUDA-related `Sema` function into new `SemaCUDA` class, following the recent example of SYCL, OpenACC, and HLSL. This is a part of the effort to split Sema. Additional context can be found in https://github.com/llvm/llvm-project/pull/82217, https://github.com/llvm/llvm-project/pull/84184, https://github.com/llvm/llvm-project/pull/87634.
2024-04-12[clang][NFC] Refactor `CUDAFunctionTarget`Vlad Serebrennikov1-4/+4
Refactor `CUDAFunctionTarget` into a scoped enum at namespace scope, so that it can be forward declared. This is done in preparation for `SemaCUDA`.
2024-04-12[clang][NFC] Refactor `CXXSpecialMember`Vlad Serebrennikov1-22/+29
In preparation for `SemaCUDA`, which requires this enum to be forward-declarable.
2024-04-12[clang][NFC] Move more functions to `SemaHLSL` (#88354)Vlad Serebrennikov1-124/+6
A follow-up to #87912. I'm moving more HLSL-related functions from `Sema` to `SemaHLSL`. I'm also dropping `HLSL` from their names in the process.
2024-04-12[RISCV] Disallow target attribute use in multiversioning (#85899)Piyou Chen1-1/+7
For RISC-V target only `target_clones` and `target_version` can enable function multiversion(FMV). This patch make target attribute trigger redefinition instead of emit FMV. Here is spec https://github.com/riscv-non-isa/riscv-c-api-doc/blob/master/riscv-c-api.md#__attribute__targetattr-string
2024-04-11[Clang][Sema] Implement approved resolution for CWG2858 (#88042)Krystian Stasiowski1-7/+6
The approved resolution for CWG2858 changes [expr.prim.id.qual] p2 sentence 2 to read: > A declarative _nested-name-specifier_ shall not have a _computed-type-specifier_. This patch implements the approved resolution. Since we don't consider _nested-name-specifiers_ in friend declarations to be declarative (yet), it currently isn't possible to write a test that would produce this diagnostic (`diagnoseQualifiedDeclaration` is never called if the `DeclContext` can't be computed). Nevertheless, tests were added which will produce the diagnostic once we start calling `diagnoseQualifiedDeclaration` for friend declarations.
2024-04-11[NFC][Clang] Improve const correctness for IdentifierInfo (#79365)Bill Wendling1-10/+11
The IdentifierInfo isn't typically modified. Use 'const' wherever possible.
2024-04-10[Clang][AArch64] Warn when calling non/streaming about vector size ↵Dinar Temirbulatov1-1/+11
difference (#79842) The compiler doesn't know in advance if the streaming and non-streaming vector-lengths are different, so it should be safe to give a warning diagnostic to warn the user about possible undefined behaviour. If the user knows the vector lengths are equal, they can disable the warning separately.
2024-04-05[Clang][Sema] Skip checking anonymous enum in using enum declaration (#87144)Qizhi Hu1-0/+4
Try to fix https://github.com/llvm/llvm-project/issues/86790 `getFETokenInfo` requires `DeclarationName` shouldn't be empty and this will produce crash when checking name conflict of an anonymous `NamedDecl` in `Sema::PushOnScopeChains` and whether it's a reserved identifier or not. These wouldn't happen when it's a anonymous enum and we can skip the checking and just add the declaration to current scope. Co-authored-by: huqizhi <836744285@qq.com>
2024-04-04[Clang][Sema] Warn unused cxx vardecl which entirely consists condition expr ↵Youngsuk Kim1-2/+15
of if/while/for construct (#87348) Emit `-Wunused-but-set-variable` warning on C++ variables whose declaration (with initializer) entirely consist the condition expression of a if/while/for construct but are not actually used in the body of the if/while/for construct. Fixes #41447
2024-04-02[Clang][Sema] Fix explicit specializations of member function templates with ↵Krystian Stasiowski1-17/+29
a deduced return type (#86817) Clang erroneously rejects the following: ``` template<typename T> struct A { template<typename U> auto f(); }; template<> template<typename U> auto A<int>::f(); // error: conflicting types for 'f' ``` This happens because the explicit specialization of `f` has its return type replaced with a dependent `AutoType` in `ActOnFunctionDeclarator`, but no such replacement occurs for the implicitly instantiated function template `A<int>::f`. Since the return types don't match, the explicit specialization is diagnosed as an invalid redeclaration. This patch moves the replacement of the return type to `CheckFunctionDeclaration` so it also happens during instantiation. `setObjectOfFriendDecl` will have been called by then, so the `isFriend && CurContext->isDependentContext()` condition is made redundant & removed (as it already happens in `DeclContext::isDependentContext`). `Sema::IsOverload` only checks the _declared_ return type (which isn't changed by the adjustment), so adjusting the return type afterwards should be safe.
2024-04-02Reapply "[clang][nullability] allow _Nonnull etc on nullable class types ↵Sam McCall1-1/+3
(#82705)" (#87325) This reverts commit 28760b63bbf9e267713957105a8d17091fb0d20e. The last commit was missing the new testcase, now fixed.