aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/Sema.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-11-03[clang][NFC] Refactor `TagTypeKind` (#71160)Vlad Serebrennikov1-2/+3
This patch converts TagTypeKind into scoped enum. Among other benefits, this allows us to forward-declare it where necessary.
2023-10-31[clang][NFC] Refactor `ArrayType::ArraySizeModifier`Vlad Serebrennikov1-2/+2
This patch moves `ArraySizeModifier` before `Type` declaration so that it's complete at `ArrayTypeBitfields` declaration. It's also converted to scoped enum along the way.
2023-10-25[Sema] -Wzero-as-null-pointer-constant: don't warn for __null (#69126)Arseny Kapoulkine1-1/+7
The implementation of -Wzero-as-null-pointer-constant was done before the following fix has been committed to GCC: https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=752e7593b0f19af233a0b7e72daab8413662b605;hp=298434c916c14e8adca2cab8a746aee29038c5b3 As a result, clang and gcc diverge on the use of `__null` and, consequently, on the use of `NULL` on systems like Linux/macOS where `NULL` is defined as `__null`. This is a problem for compatibility between gcc and clang, particularly for code bases that support C++98 or for single-source libraries that are implemented in C, but compiled as C++ via inclusion into a C++ translation unit. Code like this can not be changed to use `nullptr`, as it needs to maintain compatibility with C before C23 or C++ before C++11, but warns on the use of `NULL` in clang. The warning `Wzero-as-null-pointer-constant` is still useful with this change, as it allows to change `0` to `NULL`, which fixes gcc warnings and helps the reader distinguish between pointers and non-pointers. Users who require a full C++11 modernization pass can still use clang-tidy for that purpose.
2023-10-06[clang][Sema] Only check RVV types if we have them (#67669)Timm Baeder1-1/+1
isRVVType() is suprisingly expensive, so do the checks only if the target has rvv types.
2023-10-05[Clang] Handle consteval expression in array bounds expressions (#66222)cor3ntin1-1/+0
The bounds of a c++ array is a _constant-expression_. And in C++ it is also a constant expression. But we also support VLAs, ie arrays with non-constant bounds. We need to take care to handle the case of a consteval function (which are specified to be only immediately called in non-constant contexts) that appear in arrays bounds. This introduces `Sema::isAlwayConstantEvaluatedContext`, and a flag in ExpressionEvaluationContextRecord, such that immediate functions in array bounds are always immediately invoked. Sema had both `isConstantEvaluatedContext` and `isConstantEvaluated`, so I took the opportunity to cleanup that. The change in `TimeProfilerTest.cpp` is an unfortunate manifestation of the problem that #66203 seeks to address. Fixes #65520
2023-09-29[NFC] [C++20] [Modules] Rename NamedModuleHasInit to NamedModuleHasInitChuanqi Xu1-9/+10
Address comments in https://github.com/llvm/llvm-project/pull/67638/files#r1340342453 to rename the field variable.
2023-09-28[C++20] [Modules] Don't generate call to an imported module that dont init ↵Chuanqi Xu1-0/+21
anything (#67638) Close https://github.com/llvm/llvm-project/issues/56794 And see https://github.com/llvm/llvm-project/issues/67582 for a detailed backgrond for the issue. As required by the Itanium ABI, the module units have to generate the initialization function. However, the importers are allowed to elide the call to the initialization function if they are sure the initialization function doesn't do anything. This patch implemented this semantics.
2023-09-08Reapply "[clang] NFCI: Adopt `SourceManager::getFileEntryRefForID()`"Jan Svoboda1-3/+3
This reapplies ddbcc10b9e26b18f6a70e23d0611b9da75ffa52f, except for a tiny part that was reverted separately: 65331da0032ab4253a4bc0ddcb2da67664bd86a9. That will be reapplied later on, since it turned out to be more involved. This commit is enabled by 5523fefb01c282c4cbcaf6314a9aaf658c6c145f and f0f548a65a215c450d956dbcedb03656449705b9, specifically the part that makes 'clang-tidy/checkers/misc/header-include-cycle.cpp' separator agnostic.
2023-09-06Revert "[clang] NFCI: Adopt `SourceManager::getFileEntryRefForID()`"Jan Svoboda1-3/+3
This reverts commit ddbcc10b9e26b18f6a70e23d0611b9da75ffa52f. The 'clang-tidy/checkers/misc/header-include-cycle.cpp' test started failing on Windows: https://lab.llvm.org/buildbot/#/builders/216/builds/26855.
2023-09-06[clang] NFCI: Adopt `SourceManager::getFileEntryRefForID()`Jan Svoboda1-3/+3
This commit replaces some calls to the deprecated `FileEntry::getName()` with `FileEntryRef::getName()` by swapping current usages of `SourceManager::getFileEntryForID()` with `SourceManager::getFileEntryRefForID()`. This lowers the number of usages of the deprecated `FileEntry::getName()` from 95 to 50.
2023-09-04Add support of Windows Trace Logging macrosRichard Dzenis1-12/+0
Consider the following code: #include <windows.h> #include <TraceLoggingActivity.h> #include <TraceLoggingProvider.h> #include <winmeta.h> TRACELOGGING_DEFINE_PROVIDER( g_hMyComponentProvider, "SimpleTraceLoggingProvider", // {0205c616-cf97-5c11-9756-56a2cee02ca7} (0x0205c616,0xcf97,0x5c11,0x97,0x56,0x56,0xa2,0xce,0xe0,0x2c,0xa7)); void test() { TraceLoggingFunction(g_hMyComponentProvider); } int main() { TraceLoggingRegister(g_hMyComponentProvider); test(); TraceLoggingUnregister(g_hMyComponentProvider); } It compiles with MSVC, but clang-cl reports an error: C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\shared/TraceLoggingActivity.h(377,30): note: expanded from macro '_tlgThisFunctionName' #define _tlgThisFunctionName __FUNCTION__ ^ .\tl.cpp(14,5): error: cannot initialize an array element of type 'char' with an lvalue of type 'const char[5]' TraceLoggingFunction(g_hMyComponentProvider); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The second commit is not needed to support above code, however, during isolated tests in ms_predefined_expr.cpp I found that MSVC accepts code with constexpr, whereas clang-cl does not. I see that in most places PredefinedExpr is supported in constant evaluation, so I didn't wrap my code with ``if(MicrosoftExt)``. Reviewed By: cor3ntin Differential Revision: https://reviews.llvm.org/D158591
2023-09-04[clang][Sema] Fix a copy/paste bug in ~Sema()Timm Bäder1-1/+1
Differential Revision: https://reviews.llvm.org/D158361
2023-08-20[clang][Sema][NFC] Make some locals const in getUndefinedButUsed()Timm Bäder1-2/+2
2023-08-09Enable concatenation of predefined identifiersRichard Dzenis1-0/+12
Predefined identifiers like __FUNCTION__ are treated like string literals in MSVC, which means they can be concatentated together with an adjacent string literal. Clang now supports this behavior as well, in Microsoft extensions mode. Fixes https://github.com/llvm/llvm-project/issues/63563 Differential Revision: https://reviews.llvm.org/D153914
2023-07-10[OpenMP][OMPIRBuilder] Rename IsEmbedded and IsTargetCodegen flagsSergio Afonso1-3/+5
This patch renames the `OpenMPIRBuilderConfig` flags to reduce confusion over their meaning. `IsTargetCodegen` becomes `IsGPU`, whereas `IsEmbedded` becomes `IsTargetDevice`. The `-fopenmp-is-device` compiler option is also renamed to `-fopenmp-is-target-device` and the `omp.is_device` MLIR attribute is renamed to `omp.is_target_device`. Getters and setters of all these renamed properties are also updated accordingly. Many unit tests have been updated to use the new names, but an alias for the `-fopenmp-is-device` option is created so that external programs do not stop working after the name change. `IsGPU` is set when the target triple is AMDGCN or NVIDIA PTX, and it is only valid if `IsTargetDevice` is specified as well. `IsTargetDevice` is set by the `-fopenmp-is-target-device` compiler frontend option, which is only added to the OpenMP device invocation for offloading-enabled programs. Differential Revision: https://reviews.llvm.org/D154591
2023-06-26[Clang][RISCV] Check type support for local variable declaration of RVV typeeopXD1-14/+2
Guard local variable declaration for RVV intrinsic types. Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D153510
2023-06-23[clang][Sema] Fix comments to conform to bugprone-argument-comment (NFC)Takuya Shimizu1-4/+4
Makes some comments conform to bugprone-argument-comment (https://clang.llvm.org/extra/clang-tidy/checks/bugprone/argument-comment.html)
2023-06-16[clang][Sema] Provide source range to several Wunused warningsTakuya Shimizu1-9/+20
When the diagnosed function/variable is a template specialization, the source range covers the specialization arguments. e.g. ``` warning: unused function 'func<int>' [-Wunused-function] template <> int func<int> () {} ^~~~~~~~~ ``` This comes in line with the printed text in the warning message. In the above case, `func<int>` Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D152707
2023-06-14[clang][Sema] Fix diagnostic message for unused constant variable templatesTakuya Shimizu1-5/+4
BEFORE this patch, unused const-qualified variable templates such as `template <typename T> const double var_t = 0;` were diagnosed as `unused variable 'var_t'` This patch fixes this message to `unused variable template 'var_t'` Differential Revision: https://reviews.llvm.org/D152796
2023-06-13[Sema] Remove unused member variable MSVCGuidDeclKazu Hirata1-3/+2
The last use was removed by: commit bab6df86aefc5ea4aa3895da7cf46be37add676d Author: Richard Smith <richard@metafoo.co.uk> Date: Sat Apr 11 22:15:29 2020 -0700
2023-05-31Revert "[RISCV] Add Zvfhmin extension for clang."Craig Topper1-3/+2
This reverts commit 35a0079238ce9fc36cdc8c6a2895eb5538bf7b4a. The backend support is not present yet. The intrinsics will crash the compiler if compiled to assembly or binary.
2023-05-31[Sema] Remove unused function getFloat128IdentifierKazu Hirata1-7/+1
The last use was removed by: commit bb1ea2d6139a72340b426e114510c46d938645a6 Author: Nemanja Ivanovic <nemanja.i.ibm@gmail.com> Date: Mon May 9 08:52:33 2016 +0000 Differential Revision: https://reviews.llvm.org/D151608
2023-05-31[clang] Add Parse and Sema support for RegularKeyword attributesRichard Sandiford1-1/+1
This patch adds the Parse and Sema support for RegularKeyword attributes, following on from a previous patch that added Attr.td support. The patch is quite large. However, nothing outside the tests is specific to the first RegularKeyword attribute (__arm_streaming). The patch should therefore be a one-off, up-front cost. Other attributes just need an entry in Attr.td and the usual Sema support. The approach taken in the patch is that the keywords can be used with any language version. If standard attributes were added in language version Y, the keyword rules for version X<Y are the same as they were for version Y (to the extent possible). Any extensions beyond Y are handled in the same way for both keywords and attributes. This ensures that existing C++11 successors like C++17 are not treated differently from versions that have yet to be defined. Some notes on the implementation: * The patch emits errors rather than warnings for diagnostics that relate to keywords. * Where possible, the patch drops “attribute” from diagnostics relating to keywords. * One exception to the previous point is that warnings about C++ extensions do still mention attributes. The use there seemed OK since the diagnostics are noting a change in the production rules. * If a diagnostic string needs to be different for keywords and attributes, the patch standardizes on passing the attribute/ name/token followed by 0 for attributes and 1 for keywords. * Although the patch updates warn_attribute_wrong_decl_type_str, warn_attribute_wrong_decl_type, and warn_attribute_wrong_decl_type, only the error forms of these strings are used for keywords. * I couldn't trigger the warnings in checkUnusedDeclAttributes, even for existing attributes. An assert on the warnings caused no failures in the testsuite. I think in practice all standard attributes would be diagnosed before this. * The patch drops a call to standardAttributesAllowed in ParseFunctionDeclarator. This is because MaybeParseCXX11Attributes checks the same thing itself, where appropriate. * The new tests are based on c2x-attributes.c and cxx0x-attributes.cpp. The C++ test also incorporates a version of cxx11-base-spec-attributes.cpp. The FIXMEs are carried across from the originals. Differential Revision: https://reviews.llvm.org/D148702
2023-05-31[RISCV] Add Zvfhmin extension for clang.Jianjian GUAN1-2/+3
This patch adds the Zvfhmin extension for clang. Reviewed By: craig.topper, michaelmaitland Differential Revision: https://reviews.llvm.org/D150253
2023-05-12[-Wunsafe-buffer-usage] Move the whole analysis to the end of a translation unitziqingluo-901-0/+2
The unsafe-buffer analysis requires a complete view of the translation unit (TU) to be conservative. So the analysis is moved to the end of a TU. A summary of changes made: add a new `IssueWarnings` function in `AnalysisBasedWarnings.cpp` for TU-based analyses. So far [-Wunsafe-buffer-usage] is the only analysis using it but there could be more. `Sema` will call the new `IssueWarnings` function at the end of parsing a TU. Reviewed by: NoQ (Artem Dergachev) Differential revision: https://reviews.llvm.org/D146342
2023-05-08[Clang] Improve compile times when forming a DeclRef outside of a capturing ↵Corentin Jabot1-0/+5
scope. The logic of whether an entity needs to be captured has become quite complex and the recent changes in https://reviews.llvm.org/D124351 ad a mesurable negative impact on compile times. However, in the absence of capturing scopes (lambda, block, region) we usually can avoid running most of that logic (except that we do need to diagnostic when a nested function refers to a local variable in the scope of the outer function.). This patch track whether there is currently an active capturing scope and exit `tryCaptureVariable` early when there isn't. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D150038
2023-05-04[clang] Use -std=c++23 instead of -std=c++2bMark de Wever1-1/+1
During the ISO C++ Committee meeting plenary session the C++23 Standard has been voted as technical complete. This updates the reference to c++2b to c++23 and updates the __cplusplus macro. Drive-by fixes c++1z -> c++17 and c++2a -> c++20 when seen. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D149553
2023-05-04[clang][Sema][NFC] Move `EnterExpressionEvaluationContext` to its own fileDavid Stone1-0/+1
Sema.h is huge. This makes a small reduction to it by moving EnterExpressionEvaluationContext into a new header, since it is an independent component. Differential Revision: https://reviews.llvm.org/D149796
2023-04-24[clang] Make access to submodules via `iterator_range`Stoorx1-1/+2
In file `clang/lib/Basic/Module.cpp` the `Module` class had `submodule_begin()` and `submodule_end()` functions to retrieve corresponding iterators for private vector of Modules. This commit removes mentioned functions, and replaces all of theirs usages with `submodules()` function and range-based for-loops. Differential Revision: https://reviews.llvm.org/D148954
2023-04-20[clang][Sema][NFC] Make a bunch of things const if possibleTimm Bäder1-18/+17
And some general code style cleanup. Differential Revision: https://reviews.llvm.org/D148696
2023-04-20[clang][Sema][NFC] Use existing TargetInfo local variableTimm Bäder1-6/+6
2023-04-17[NFC][clang] Fix coverity static analyzer concerns about AUTO_CAUSES_COPYManna, Soumi1-1/+1
Reported by Coverity: AUTO_CAUSES_COPY Unnecessary object copies can affect performance. 1. [NFC] Fix auto keyword use without an & causes the copy of an object of type SimpleRegistryEntry in clang::getAttributePluginInstances() 2. [NFC] Fix auto keyword use without an & causes the copy of an object of type tuple in CheckStmtInlineAttr<clang::NoInlineAttr, 2>(clang::Sema &, clang::Stmt const *, clang::Stmt const *, clang::AttributeCommonInfo const &) 3. [NFC] Fix auto keyword use without an & causes the copy of an object of type QualType in <unnamed>::SystemZTargetCodeGenInfo::isVectorTypeBased(clang::Type const *, bool) 4. [NFC] Fix auto keyword use without an & causes the copy of an object of type Policy in <unnamed>::RISCVIntrinsicManagerImpl::InitIntrinsicList() 5. [NFC] Fix auto keyword use without an & causes the copy of an object of type pair in checkUndefinedButUsed(clang::Sema &) Reviewed By: tahonermann Differential Revision: <https://reviews.llvm.org/D147543>
2023-04-12[Clang] Fix crash caused by line splicing in doc commentCorentin Jabot1-1/+6
Because the comment parser does not support slices, we emit a warning for comments that do contain a splice within their delimiter, and do not add them as documentation comment. Fixes #62054 Reviewed By: shafik, aaron.ballman Differential Revision: https://reviews.llvm.org/D148029
2023-03-14[clang][sema][NFC] Make a few functions constTimm Bäder1-4/+4
Differential Revision: https://reviews.llvm.org/D145947
2023-03-03[C++20] [Modules] Support to export declarations in language linkageChuanqi Xu1-2/+2
Close https://github.com/llvm/llvm-project/issues/60405 See the discussion in the above link for the background. What the patch does: - Rename `Module::ModuleKind::GlobalModuleFragment` to `Module::ModuleKind::ExplicitGlobalModuleFragment`. - Add another module kind `ImplicitGlobalModuleFragment` to `ModuleKind`. - Create an implicit global module fragment for the language linkage declarations inside a module purview. - If the language linkage lives inside the scope of an export decl, the created modules is marked as exported to outer modules. - In fact, Sema will only create at most 2 implicit global module fragments to avoid creating a lot of unnecessary modules in the edging case. Reviewed By: iains Differential Revision: https://reviews.llvm.org/D144367
2023-03-02[Clang] Implement Change scope of lambda trailing-return-typeCorentin Jabot1-3/+4
This implements P2036R3 and P2579R0. That is, explicit, int, and implicit capture become visible at the start of the parameter head. Reviewed By: aaron.ballman, rupprecht, shafik Differential Revision: https://reviews.llvm.org/D124351
2023-02-20Recommit [Coroutines] Stop supportting std::experimental::coroutine_traitsChuanqi Xu1-1/+1
As we discussed before, we should stop supporting std::experimental::coroutine_traits in clang17. Now the clang16 is branched so we can clean them now. All the removed tests have been duplicated before.
2023-02-17[WebAssembly] Initial support for reference type externref in clangPaulo Matos1-0/+7
This patch introduces a new type __externref_t that denotes a WebAssembly opaque reference type. It also implements builtin __builtin_wasm_ref_null_extern(), that returns a null value of __externref_t. This lays the ground work for further builtins and reference types. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D122215
2023-02-17Revert "[Coroutines] Stop supportting std::experimental::coroutine_traits"Chuanqi Xu1-1/+1
This reverts commit c4e6e771f255fb1da3d505534997b6a88195b012. Since clang-tools-extra contains the use for std::experimental::coroutine_traits, the previsou commit breaks the build bot. Revert this one to make the bot green.
2023-02-17[Coroutines] Stop supportting std::experimental::coroutine_traitsChuanqi Xu1-1/+1
As we discussed before, we should stop supporting std::experimental::coroutine_traits in clang17. Now the clang16 is branched so we can clean them now. All the removed tests have been duplicated before.
2023-02-16[Modules] Code cleanup after removing ModulesTSChuanqi Xu1-2/+1
Some codes become unused after we remove ModulesTS.
2023-02-16[Modules] Remove -fmodules-tsChuanqi Xu1-10/+0
As the diagnostic message shows, we should remove -fmodules-ts flag in clang/llvm17. Since clang/llvm16 is already branched. We can remove the depreacared flag now.
2023-02-14[Clang][RISCV] Guard vector int64, float32, float64 with semantic analysiseopXD1-2/+11
Depends on D143657 Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D143665
2023-02-13[Clang][RISCV] Guard vector float16 type correctly with semantic analysiseopXD1-0/+6
Before this commit, vector float 16 types (e.g. `vfloat16m1_t`) of RVV is only defined when extension `zvfh` is defined. However this generate inaccurate diagnostics like: ``` error: unknown type name 'vfloat16m1_t' ``` This commit improves the compiler by guarding type check correctly under semantic analysis. Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D143657
2023-02-05Revert "[clang][WebAssembly] Initial support for reference type externref in ↵Vitaly Buka1-7/+0
clang" Very likely breaks stage 3 of msan build bot. Good: 764c88a50ac76a2df2d051a0eb5badc6867aabb6 https://lab.llvm.org/buildbot/#/builders/74/builds/17058 Looks unrelated: 48b5a06dfcab12cf093a1a3df42cb5b684e2be4c Bad: 48b5a06dfcab12cf093a1a3df42cb5b684e2be4c https://lab.llvm.org/buildbot/#/builders/74/builds/17059 This reverts commit eb66833d19573df97034a81279eda31b8d19815b.
2023-02-03Revert "[Clang] Implement Change scope of lambda trailing-return-type"Jordan Rupprecht1-4/+3
This reverts commit d708a186b6a9b050d09558163dd353d9f738c82d (and typo fix e4bc9898ddbeb70bc49d713bbf863f050f21e03f). It causes a compilation error for this: ``` struct StringLiteral { template <int N> StringLiteral(const char (&array)[N]) __attribute__((enable_if(N > 0 && N == __builtin_strlen(array) + 1, "invalid string literal"))); }; struct Message { Message(StringLiteral); }; void Func1() { auto x = Message("x"); // Note: this is fine // Note: "xx\0" to force a different type, StringLiteral<3>, otherwise this // successfully builds. auto y = [&](decltype(Message("xx"))) {}; // ^ fails with: repro.cc:18:13: error: reference to local variable 'array' // declared in enclosing function 'StringLiteral::StringLiteral<3>' (void)x; (void)y; } ``` More details posted to D124351.
2023-01-31[clang][WebAssembly] Initial support for reference type externref in clangPaulo Matos1-0/+7
This patch introduces a new type __externref_t that denotes a WebAssembly opaque reference type. It also implements builtin __builtin_wasm_ref_null_extern(), that returns a null value of __externref_t. This lays the ground work for further builtins and reference types. Differential Revision: https://reviews.llvm.org/D122215
2023-01-31[Clang] Implement Change scope of lambda trailing-return-typeCorentin Jabot1-3/+4
This implements P2036R3 and P2579R0. That is, explicit, int, and implicit capture become visible at the start of the parameter head. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D124351
2023-01-25[Clang] Fix compilation errors for unsupported __bf16 intrinsicsElizabeth Andrews1-0/+2
This patch uses existing deferred diagnostics framework to emit error for unsupported type __bf16 in device code. Error is not emitted in host code. Differential Revision: https://reviews.llvm.org/D141375
2023-01-14[clang] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-3/+3
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716