aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaDecl.cpp
AgeCommit message (Collapse)AuthorFilesLines
2024-09-24[C++20][Modules] NFC Reworked handling of inline for functions defined in ↵tomasz-kaminski-sonarsource1-8/+8
class (#109470) Reworked handling of implicit inline marking for member and friend function defined in class. Now, we handle it in an additive manner, i.e. if such in-class functions are inline implicitly by language rules, we mark the as `setImplicitInline`, and perform no action otherwise. As we never remove inline specifier, the implementation is orthogonal to other sources of inline (like `inline`, `constexpr`, e.t.c), and we do not need to handle them specially. Also included test for `constexpr`, `consteval` and global module cases.
2024-09-24[clang][NFC] add static for internal linkage function (#109436)Congcong Cai1-1/+1
Detected by clang-tidy misc-use-internal-linkage
2024-09-21Revert "[Clang][Sema] Refactor collection of multi-level template argument ↵Martin Storsjö1-14/+17
lists (#106585)" This reverts commit cdd71d61664b63ae57bdba9ee0d891f78ef79c07 (and 30adb43c897a45c18d7dd163fb4ff40c915fc488). This change broke compiling Qt, see https://github.com/llvm/llvm-project/pull/106585#issuecomment-2365309463 for details.
2024-09-20[Clang][Sema] Refactor collection of multi-level template argument lists ↵Krystian Stasiowski1-17/+14
(#106585) Currently, clang rejects the following explicit specialization of `f` due to the constraints not being equivalent: ``` template<typename T> struct A { template<bool B> void f() requires B; }; template<> template<bool B> void A<int>::f() requires B { } ``` This happens because, in most cases, we do not set the flag indicating whether a `RedeclarableTemplate` is an explicit specialization of a member of an implicitly instantiated class template specialization until _after_ we compare constraints for equivalence. This patch addresses the issue (and a number of other issues) by: - storing the flag indicating whether a declaration is a member specialization on a per declaration basis, and - significantly refactoring `Sema::getTemplateInstantiationArgs` so we collect the right set of template argument in all cases. Many of our declaration matching & constraint evaluation woes can be traced back to bugs in `Sema::getTemplateInstantiationArgs`. This change/refactor should fix a lot of them. It also paves the way for fixing #101330 and #105462 per my suggestion in #102267 (which I have implemented on top of this patch but will merge in a subsequent PR).
2024-09-18[C++20] [Modules] Treat in class defined member functions in language ↵Chuanqi Xu1-1/+1
linkage as implicitly inline Close https://github.com/llvm/llvm-project/issues/108732 This looks liek an oversight mostly.
2024-09-13[clang][C23] Support N3029 Improved Normal Enumerations (#103917)Mariya Podchishchaeva1-23/+35
Basically clang already implemented 90% of the feature as an extension. This commit disables warnings for C23 and aligns types of enumerators according to the recent wording.
2024-09-09[C++20] [Modules] Treat constexpr/consteval member function as implicitly inlineChuanqi Xu1-0/+1
Close https://github.com/llvm/llvm-project/issues/107673
2024-09-03[clang][Sema] Fix diagnostic for function overloading in extern "C" (#106033)s-watanabe3141-0/+4
Fixes #80235 When trying to overload a function within `extern "C"`, the diagnostic `functions that differ only in their return type cannot be overloaded` is given. This diagnostic is inappropriate because overloading is basically not allowed in the C language. However, if the redeclared function has the `((overloadable))` attribute, it should be diagnosed as `functions that differ only in their return type cannot be overloaded`. This patch uses `isExternC()` to provide an appropriate diagnostic during the diagnostic process. `isExternC()` updates the linkage information cache internally, so calling it before merging functions can cause clang to crash. An example is declaring `static void foo()` and `void foo()` within an `extern "C"` block. Therefore, I decided to call `isExternC()` after the compilation error is confirmed and select the diagnostic message. The diagnostic message is `conflicting types for 'func'` similar to the diagnostic in C, and `functions that differ only in their return type cannot be overloaded` if the `((overloadable))` attribute is given. Regression tests verify that the expected diagnostics are given when trying to overload functions within `extern "C"` and when the `((overloadable))` attribute is present. --------- Co-authored-by: Sirraide <aeternalmail@gmail.com>
2024-08-31[HLSL] Implement output parameter (#101083)Chris B1-20/+16
HLSL output parameters are denoted with the `inout` and `out` keywords in the function declaration. When an argument to an output parameter is constructed a temporary value is constructed for the argument. For `inout` pamameters the argument is initialized via copy-initialization from the argument lvalue expression to the parameter type. For `out` parameters the argument is not initialized before the call. In both cases on return of the function the temporary value is written back to the argument lvalue expression through an implicit assignment binary operator with casting as required. This change introduces a new HLSLOutArgExpr ast node which represents the output argument behavior. The OutArgExpr has three defined children: - An OpaqueValueExpr of the argument lvalue expression. - An OpaqueValueExpr of the copy-initialized parameter. - A BinaryOpExpr assigning the first with the value of the second. Fixes #87526 --------- Co-authored-by: Damyan Pepper <damyanp@microsoft.com> Co-authored-by: John McCall <rjmccall@gmail.com>
2024-08-31[HLSL] AST support for WaveSize attribute. (#101240)Xiang Li1-0/+4
First step for support WaveSize attribute in https://microsoft.github.io/DirectX-Specs/d3d/HLSL_SM_6_6_WaveSize.html and https://microsoft.github.io/hlsl-specs/proposals/0013-wave-size-range.html A new attribute HLSLWaveSizeAttr was supported in the AST. Implement both the wave size and the wave size range, rather than separately which might require more work. For #70118
2024-08-29[NFC][Clang] Avoid potential null pointer dereferences in ↵Tom Honermann1-8/+7
Sema::AddInitializerToDecl(). (#106235) Control flow analysis performed by a static analysis tool revealed the potential for null pointer dereferences to occur in conjunction with the `Init` parameter in `Sema::AddInitializerToDecl()`. On entry to the function, `Init` is required to be non-null as there are multiple potential branches that unconditionally dereference it. However, there were two places where `Init` is compared to null thus implying that `Init` is expected to be null in some cases. These checks appear to be purely defensive checks and thus unnecessary. Further, there were several cases where code checked `Result`, a variable of type `ExprResult`, for an invalid value, but did not check for a valid but null value and then proceeded to unconditionally dereference the potential null result. This change elides the unnecessary defensive checks and changes some checks for an invalid result to instead branch on an unusable result (either an invalid result or a valid but null result).
2024-08-28[clang] Add lifetimebound attr to std::span/std::string_view constructor ↵Haojian Wu1-19/+1
(#103716) With this patch, clang now automatically adds ``[[clang::lifetimebound]]`` to the parameters of `std::span, std::string_view` constructors, this enables Clang to capture more cases where the returned reference outlives the object. Fixes #100567
2024-08-22[Clang][Sema] Rebuild template parameters for out-of-line template ↵Krystian Stasiowski1-0/+6
definitions and partial specializations (#104030) We need to rebuild the template parameters of out-of-line definitions/specializations of member templates in the context of the current instantiation for the purposes of declaration matching. We already do this for function templates and class templates, but not variable templates, partial specializations of variable template, and partial specializations of class templates. This patch fixes the latter cases.
2024-08-18[Clang] Do not allow `[[clang::lifetimebound]]` on explicit object member ↵Mital Ashok1-2/+9
functions (#96113) Previously, `[[clang::lifetimebound]]` applied to an explicit object member function did nothing and was silently ignored. Now issue the error diagnostic `'lifetimebound' attribute cannot be applied; explicit object member function has no implicit object parameter`
2024-08-17[clang][NFC] Clean up `Sema` headersVlad Serebrennikov1-0/+1
When various `Sema*.h` and `Sema*.cpp` files were created, cleanup of `Sema.h` includes and forward declarations was left for the later. Now's the time. This commit touches `Sema.h` and Sema components: 1. Unused includes are removed. 2. Unused forward declarations are removed. 3. Missing includes are added (those files are largely IWYU-clean now). 4. Includes were converted into forward declarations where possible. As this commit focuses on headers, all changes to `.cpp` files were minimal, and were aiming at keeping everything buildable.
2024-08-17[Clang] fix crash by avoiding invalidation of extern main declaration during ↵Oleksandr T.1-4/+1
strictness checks (#104594) Fixes #104570
2024-08-15[Clang] [Sema] Error on reference types inside a union with msvc 1900+ (#102851)Max Winkler1-5/+9
Godbolt for reference: https://godbolt.org/z/ovKjvWc46 I can confirm that this extension is no longer valid in VS2017, VS2019 and VS2022 under `/permissive` and `/permissive-` MSDN, https://learn.microsoft.com/en-us/cpp/porting/visual-cpp-what-s-new-2003-through-2015?view=msvc-170, says this extension was officially removed in VS2015.
2024-08-15[Clang] Implement C++26’s P2893R3 ‘Variadic friends’ (#101448)Sirraide1-2/+6
Implement P2893R3 ‘Variadic friends’ for C++26. This closes #98587. Co-authored-by: Younan Zhang <zyn7109@gmail.com>
2024-08-08Reland [C++20] [Modules] [Itanium ABI] Generate the vtable in the mod… ↵Chuanqi Xu1-0/+9
(#102287) Reland https://github.com/llvm/llvm-project/pull/75912 The differences of this PR between https://github.com/llvm/llvm-project/pull/75912 are: - Fixed a regression in `Decl::isInAnotherModuleUnit()` in DeclBase.cpp pointed by @mizvekov and add the corresponding test. - Fixed the regression in windows https://github.com/llvm/llvm-project/issues/97447. The changes are in `CodeGenModule::getVTableLinkage` from `clang/lib/CodeGen/CGVTables.cpp`. According to the feedbacks from MSVC devs, the linkage of vtables won't affected by modules. So I simply skipped the case for MSVC. Given this is more or less fundamental to the use of modules. I hope we can backport this to 19.x.
2024-08-08[Clang] Strengthen checks for `main` to meet `[basic.start.main]p3`’s ↵Oleksandr T.1-8/+29
requirements (#101853) Fixes #101512.
2024-08-06[Clang][Sema] Make UnresolvedLookupExprs in class scope explicit ↵Krystian Stasiowski1-1/+1
specializations instantiation dependent (#100392) A class member named by an expression in a member function that may instantiate to a static _or_ non-static member is represented by a `UnresolvedLookupExpr` in order to defer the implicit transformation to a class member access expression until instantiation. Since `ASTContext::getDecltypeType` only creates a `DecltypeType` that has a `DependentDecltypeType` as its canonical type when the operand is instantiation dependent, and since we do not transform types unless they are instantiation dependent, we need to mark the `UnresolvedLookupExpr` as instantiation dependent in order to correctly build a `DecltypeType` using the expression as its operand with a `DependentDecltypeType` canonical type. Fixes #99873.
2024-08-06[Clang][Sema] Ensure that the selected candidate for a member function ↵Krystian Stasiowski1-3/+4
explicit specialization is more constrained than all others (#101721) The selection of the most constrained candidate for member function explicit specializations introduced in #88963 does not check whether the selected candidate is more constrained than all other candidates, which can result in ambiguities being undiagnosed. This patch addresses the issue.
2024-08-05[HLSL] Implement intangible AST type (#97362)Helena Kotas1-6/+13
HLSL has a set of intangible types which are described in in the [draft HLSL Specification (**[Basic.types]**)](https://microsoft.github.io/hlsl-specs/specs/hlsl.pdf): There are special implementation-defined types such as handle types, which fall into a category of standard intangible types. Intangible types are types that have no defined object representation or value representation, as such the size is unknown at compile time. A class type T is an intangible class type if it contains an base classes or members of intangible class type, standard intangible type, or arrays of such types. Standard intangible types and intangible class types are collectively called intangible types([9](https://microsoft.github.io/hlsl-specs/specs/hlsl.html#Intangible)). This PR implements one standard intangible type `__hlsl_resource_t` and sets up the infrastructure that will make it easier to add more in the future, such as samplers or raytracing payload handles. The HLSL intangible types are declared in `clang/include/clang/Basic/HLSLIntangibleTypes.def` and this file is included with related macro definition in most places that require edits when a new type is added. The new types are added as keywords and not typedefs to make sure they cannot be redeclared, and they can only be declared in builtin implicit headers. The `__hlsl_resource_t` type represents a handle to a memory resource and it is going to be used in builtin HLSL buffer types like this: template <typename T> class RWBuffer { [[hlsl::contained_type(T)]] [[hlsl::is_rov(false)]] [[hlsl::resource_class(uav)]] __hlsl_resource_t Handle; }; Part 1/3 of llvm/llvm-project#90631. --------- Co-authored-by: Justin Bogner <mail@justinbogner.com>
2024-08-04[clang] Construct SmallVector with ArrayRef (NFC) (#101898)Kazu Hirata1-1/+1
2024-08-02[Clang] prevent assertion failure by avoiding required literal type checking ↵Oleksandr T.1-1/+2
in C context (#101426) Fixes #101304
2024-07-31[clang][NFC] Add Type::isPointerOrReferenceType() (#101206)Timm Baeder1-6/+6
Seems to be a common pattern.
2024-07-27[clang][ARM64EC] Add support for hybrid_patchable attribute. (#99478)Jacek Caban1-0/+5
2024-07-26[clang][FMV][AArch64] Improve streaming mode compatibility. (#100181)Alexandros Lamprineas1-4/+20
* Allow arm-streaming if all the functions versions adhere to it. * Allow arm-streaming-compatible if all the functions versions adhere to it. When the caller needs to toggle the streaming mode all the function versions of the callee must adhere to the same mode, otherwise the call will yield a runtime error. Imagine the versions of the callee live in separate TUs. The version that is visible to the caller will determine the calling convention used when generating code for the callsite. Therefore we cannot support mixing streaming with non-streaming function versions. Imagine TU1 has a streaming caller and calls foo._sme which is streaming-compatible. The codegen for the callsite will not switch off the streaming mode. Then in TU2 we have a version which is non-streaming and could potentially be called in streaming mode. Similarly if the caller is non-streaming and the called version is streaming-compatible the codegen for the callsite will not switch on the streaming mode, but other versions may be streaming.
2024-07-25[clang][CUDA] Assume unknown emission status for skipped function ↵kadir çetinkaya1-2/+4
definitions (#100124) Emission status seems to be only used by cuda/openmp/hip compiles, to figure out when to emit diagnostics. Current logic emits "uknown" when definition is missing, so i extended that to skipped-function-bodies as well.
2024-07-18[clang] Fix crash in concept deprecation (#98622)Vlad Serebrennikov1-4/+4
There is a gap between `getAs<AutoType>()` and `getConstrainedAutoType()` that the original patch #92295 was not aware of. Fixes #98164
2024-07-17[Sema] Don't drop weak_import from a declaration if its definition isn't ↵Akira Hatanaka1-9/+11
seen (#85886) I believe this is what the original commit (33e022650adee965c65f9aea086ee74f3fd1bad5) was trying to do. This fixes a bug where clang removes the attribute from a declaration that follows a declaration directly contained in a linkage-specification. rdar://61865848
2024-07-17Performance optimizations for function effects (nonblocking attribute etc.) ↵Doug Wyatt1-36/+38
(#96844) - Put new FunctionProtoType trailing objects last. - Inline FunctionEffectsRef::get() - Manually inline FunctionEffectsRef::Profile(). --------- Co-authored-by: Doug Wyatt <dwyatt@apple.com>
2024-07-17[Clang] Add attribute for consteval builtin functions (#91894)Mital Ashok1-4/+11
Builtins with the new `Consteval` attribute will also be marked `Constexpr` and will only be available in C++20 mode where `consteval` makes sense.
2024-07-12Revert "[clang] Catch missing format attributes" (#98617)Aaron Ballman1-2/+0
Reverts llvm/llvm-project#70024 It broke several post-commit bots: https://lab.llvm.org/buildbot/#/builders/193/builds/896 https://lab.llvm.org/buildbot/#/builders/23/builds/925 https://lab.llvm.org/buildbot/#/builders/13/builds/686 and others
2024-07-12[clang] Catch missing format attributes (#70024)Budimir Aranđelović1-0/+2
Enable flag -Wmissing-format-attribute to catch missing attributes. Fixes #60718
2024-07-12[C++20] [Modules] Allow export redeclarations within language linkageChuanqi Xu1-0/+9
Close https://github.com/llvm/llvm-project/issues/98583 Currently, clang will reject the following code: ``` export module mod; extern "C++" void func(); export extern "C++" { void func(); } ``` while both MSVC and GCC accept it. Although clang's behavior matches the current wording, from the discussion, the consensus is that we should accept the above example from the intention. Since the intention to not allow export redeclaration which is not exported is to make the linkage clear. But it doesn't matter with the declarations within global module.
2024-07-12[NFC] [Modules] Introduce 'DeclBase::isInNamedModule' interfaceChuanqi Xu1-1/+1
This patch introduces DeclBase::isInNamedModule API to ease the use of modules slightly.
2024-07-11[C++20][Modules] static data members of template classes should be allowed ↵Dmitry Polukhin1-1/+2
in header units (#98309) Summary: There is no sense to report these cases as an error or add `inline` explicitly in these cases, if it is not required in normal headers. Similar to #60079. Test Plan: check-clang
2024-07-10Revert "[C++20] [Modules] [Itanium ABI] Generate the vtable in the module ↵Chuanqi Xu1-10/+1
unit of dynamic classes (#75912)" This reverts commit 18f3bcbb13ca83d33223b00761d8cddf463e9ffb, 15bb02650e26875c48889053d6a9697444583721 and 99873b35da7ecb905143c8a6b8deca4d4416f1a9. See the post commit message in https://github.com/llvm/llvm-project/pull/75912 to see the reasons.
2024-07-09Fix erroneous `-Wmissing-prototypes` for Win32 entry points (#98105)Max Winkler1-0/+3
Fixes https://github.com/llvm/llvm-project/issues/94366.
2024-07-05[BPF] Fix linking issues in static map initializers (#91310)Nick Zavaritsky1-0/+8
When BPF object files are linked with bpftool, every symbol must be accompanied by BTF info. Ensure that extern functions referenced by global variable initializers are included in BTF. The primary motivation is "static" initialization of PROG maps: ```c extern int elsewhere(struct xdp_md *); struct { __uint(type, BPF_MAP_TYPE_PROG_ARRAY); __uint(max_entries, 1); __type(key, int); __type(value, int); __array(values, int (struct xdp_md *)); } prog_map SEC(".maps") = { .values = { elsewhere } }; ``` BPF backend needs debug info to produce BTF. Debug info is not normally generated for external variables and functions. Previously, it was solved differently for variables (collecting variable declarations in ExternalDeclarations vector) and functions (logic invoked during codegen in CGExpr.cpp). This patch generalises ExternalDefclarations to include both function and variable declarations. This change ensures that function references are not missed no matter the context. Previously external functions referenced in constant expressions lacked debug info.
2024-07-04[clang][FMV] Do not omit explicit default target_version attribute. (#96628)Alexandros Lamprineas1-51/+23
Fixes a crash and cleans up some dead code. namespace Foo { int bar(); __attribute((target_version("default"))) int bar() { return 0; } __attribute((target_version("mops"))) int bar() { return 1; } } $ clang++ --target=aarch64-linux-gnu --rtlib=compiler-rt fmv.cpp None multiversion type isn't valid here UNREACHABLE executed at clang/lib/CodeGen/CodeGenModule.cpp:1840! ... getMangledNameImpl clang::CodeGen::CodeGenModule::getMangledName clang::CodeGen::CodeGenModule::EmitGlobal
2024-07-01Revert "[clang][AST] fix ast-print of extern <lang> with >=2 declarators"Aaron Ballman1-1/+1
This reverts commit 48f13d48a88c14acbaea7c3ee05018bb173fb360. It broke some external bots: https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/6805/console https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8743609724828014497/+/u/clang/build/stdout
2024-07-01[clang][NFC] Move documentation of `Sema` functions into `Sema.h`Vlad Serebrennikov1-368/+1
This patch moves documentation of `Sema` functions from `.cpp` files to `Sema.h` when there was no documentation in the latter, or it can be trivially subsumed. More complicated cases when there's less trivial divergence between documentation attached to declaration and the one attached to implementation are left for a later PR that would require review. It appears that doxygen can find the documentation for a function defined out-of-line even if it's attached to an implementation, and not declaration. But other tools, e.g. clangd, are not as powerful. So this patch significantly improves autocompletion experience for (at least) clangd-based IDEs.
2024-07-01[clang][AST] fix ast-print of extern <lang> with >=2 declaratorstemyurchenko1-1/+1
Fixes #93913
2024-06-24[Clang] Introduce `nonblocking`/`nonallocating` attributes (#84983)Doug Wyatt1-2/+103
Introduce `nonblocking` and `nonallocating` attributes. RFC is here: https://discourse.llvm.org/t/rfc-nolock-and-noalloc-attributes/76837 This PR introduces the attributes, with some changes in Sema to deal with them as extensions to function (proto)types. There are some basic type checks, most importantly, a warning when trying to spoof the attribute (implicitly convert a function without the attribute to one that has it). A second, follow-on pull request will introduce new caller/callee verification. --------- Co-authored-by: Doug Wyatt <dwyatt@apple.com> Co-authored-by: Shafik Yaghmour <shafik.yaghmour@intel.com> Co-authored-by: Aaron Ballman <aaron@aaronballman.com> Co-authored-by: Sirraide <aeternalmail@gmail.com>
2024-06-24[NFC] [Modules] Extract the logic to decide whether the module units belongs ↵Chuanqi Xu1-2/+1
to the same module This patch extracts the logci to decide how we decide the module units belongs to the same module into a member function of ASTContext. This is helpful to refactor the implementation in the future.
2024-06-18[Clang][Sema] Diagnose variable template explicit specializations with ↵Krystian Stasiowski1-114/+134
storage-class-specifiers (#93873) According to [temp.expl.spec] p2: > The declaration in an _explicit-specialization_ shall not be an _export-declaration_. An explicit specialization shall not use a _storage-class-specifier_ other than `thread_local`. Clang partially implements this, but a number of issues exist: 1. We don't diagnose class scope explicit specializations of variable templates with _storage-class-specifiers_, e.g. ``` struct A { template<typename T> static constexpr int x = 0; template<> static constexpr int x<void> = 1; // ill-formed, but clang accepts }; ```` 2. We incorrectly reject class scope explicit specializations of variable templates when `static` is not used, e.g. ``` struct A { template<typename T> static constexpr int x = 0; template<> constexpr int x<void> = 1; // error: non-static data member cannot be constexpr; did you intend to make it static? }; ```` 3. We don't diagnose dependent class scope explicit specializations of function templates with storage class specifiers, e.g. ``` template<typename T> struct A { template<typename U> static void f(); template<> static void f<int>(); // ill-formed, but clang accepts }; ```` This patch addresses these issues as follows: - # 1 is fixed by issuing a diagnostic when an explicit specialization of a variable template has storage class specifier - # 2 is fixed by considering any non-function declaration with any template parameter lists at class scope to be a static data member. This also allows for better error recovery (it's more likely the user intended to declare a variable template than a "field template"). - # 3 is fixed by checking whether a function template explicit specialization has a storage class specifier even when the primary template is not yet known. One thing to note is that it would be far simpler to diagnose this when parsing the _decl-specifier-seq_, but such an implementation would necessitate a refactor of `ParsedTemplateInfo` which I believe to be outside the scope of this patch.
2024-06-18[clang][NFC] Use foreach loop in FinalizeDeclaratorGroupTimm Bäder1-43/+43
2024-06-17[C++20] [Modules] [Itanium ABI] Generate the vtable in the module unit of ↵Chuanqi Xu1-0/+9
dynamic classes (#75912) Close https://github.com/llvm/llvm-project/issues/70585 and reflect https://github.com/itanium-cxx-abi/cxx-abi/issues/170. The significant change of the patch is: for dynamic classes attached to module units, we generate the vtable to the attached module units directly and the key functions for such classes is meaningless.