aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaStmt.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-07-10[Sema] Fix lifetime extension for temporaries in range-based for loops in ↵Marco Vitale1-0/+1
C++23 (#145164) C++23 mandates that temporaries used in range-based for loops are lifetime-extended to cover the full loop. This patch adds a check for loop variables and compiler- generated `__range` bindings to apply the correct extension. Includes test cases based on examples from CWG900/P2644R1. Fixes https://github.com/llvm/llvm-project/issues/109793
2025-06-13Remove delayed typo expressions (#143423)Aaron Ballman1-11/+3
This removes the delayed typo correction functionality from Clang (regular typo correction still remains) due to fragility of the solution. An RFC was posted here: https://discourse.llvm.org/t/rfc-removing-support-for-delayed-typo-correction/86631 and while that RFC was asking for folks to consider stepping up to be maintainers, and we did have a few new contributors show some interest, experiments show that it's likely worth it to remove this functionality entirely and focus efforts on improving regular typo correction. This removal fixes ~20 open issues (quite possibly more), improves compile time performance by roughly .3-.4% (https://llvm-compile-time-tracker.com/?config=Overview&stat=instructions%3Au&remote=AaronBallman&sortBy=date), and does not appear to regress diagnostic behavior in a way we wouldn't find acceptable. Fixes #142457 Fixes #139913 Fixes #138850 Fixes #137867 Fixes #137860 Fixes #107840 Fixes #93308 Fixes #69470 Fixes #59391 Fixes #58172 Fixes #46215 Fixes #45915 Fixes #45891 Fixes #44490 Fixes #36703 Fixes #32903 Fixes #23312 Fixes #69874
2025-05-30[clang][NFC] Move Diags.isIgnored check later in checkForRedundantLoop (#141470)Timm Baeder1-4/+4
... Iteration. The `isIgnored()` check is more expensive than the earlier checks, so move it last.
2025-05-28[clang][Sema] Diagnose exceptions only in non-dependent context in discarded ↵Rajveer Singh Bharadwaj1-7/+19
`try/catch/throw` blocks (#139859) Resolves #138939 When enabling `--fno-exceptions` flag, discarded statements containing `try/catch/throw` in an independent context can be avoided from being rejected.
2025-05-28[clang][Sema] Cleanup and optimize DiagnoseAssignmentEnum (#141471)Timm Baeder1-45/+53
Reorder the precondition checks to move the costly onces last. Also, only evaluate the RHS once to get the integral value.
2025-05-26[clang][NFC] Call Stmt::getBeginLoc() once in DiagnoseForRangeVariable (#141472)Timm Baeder1-6/+4
...Copies. Instead of three times.
2025-05-25[Sema] Remove unused includes (NFC) (#141419)Kazu Hirata1-1/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-05-23[Sema] Warn about omitting deprecated enumerator in switch (#138562)Hans Wennborg1-1/+5
This undoes part of 3e4e3b17c14c15c23c0ed18ca9165b42b1b13ae3 which added the "Omitting a deprecated constant is ok; it should never materialize." logic. That seems wrong: deprecated means the enumerator is likely to be removed in future versions, not that it cannot materialize. Also move warnings about the use of deprecated enumerators in switch cases behind a separate flag, -Wdeprecated-switch-case, for users who wish to handle such enums explicitly and suppress the warning.
2025-05-02[clang][NFC] Convert `Sema::CCEKind` to scoped enumVlad Serebrennikov1-1/+1
2025-05-02[clang][NFC] Convert `Sema::AllowFoldKind` to scoped enumVlad Serebrennikov1-1/+1
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-05-01[clang][NFC] Convert `Sema::BuiltinCountedByRefKind` to scoped enumVlad Serebrennikov1-1/+2
2025-04-19[clang] Use llvm::unique (NFC) (#136469)Kazu Hirata1-4/+2
2025-04-14[Clang][Sema]:Fix musttail attribute on a function with not_tail_called ↵MillePlateaux1-0/+7
attribute has no warning/error (#134465) The error is emitted when a musttail call is made to a function marked with the not_tail_called attribute.Closes #133509
2025-03-21Reland: [clang] NFC: Clear some uses of MemberPointerType::getClass (#132317)Matheus Izvekov1-1/+2
Relands Original PR: https://github.com/llvm/llvm-project/pull/131965 Addresses https://github.com/llvm/llvm-project/pull/131965#issuecomment-2741619498 * Fixes isIncompleteType for injected classes This clears up some uses of getClass on MemberPointerType when equivalent uses of getMostRecentCXXRecordDecl would be just as simple or simpler. This is split-off from a larger patch which removes getClass, in order to facilitate review.
2025-03-20Revert "[clang] NFC: Clear some uses of MemberPointerType::getClass" (#132281)Matheus Izvekov1-2/+1
Reverts llvm/llvm-project#131965 Reverted due to issue reported here: https://github.com/llvm/llvm-project/pull/131965#issuecomment-2741619498
2025-03-19[clang] NFC: Clear some uses of MemberPointerType::getClass (#131965)Matheus Izvekov1-1/+2
2025-03-15[Clang] Do not emit nodiscard warnings for the base expr of static member ↵cor3ntin1-4/+0
access (#131450) For an expression `nodiscard_function().static_member(), the nodiscard warnings added by #120223, are not useful or actionable, and are disruptive to some library implementations; we just remove them. Fixes #131410
2025-03-07[C2y] Implement WG14 N3409 (#130299)Aaron Ballman1-2/+2
This paper removes UB around use of void expressions. Previously, code like this had undefined behavior: ``` void foo(void) { (void)(void)1; extern void x; x; } ``` and this is now well-defined in C2y. Functionally, this now means that it is valid to use `void` as a `_Generic` association.
2025-03-06[Clang] [Sema] Allow non-local/non-variable declarations in for loop (#129737)Sirraide1-5/+8
Currently, we error on non-variable or non-local variable declarations in `for` loops such as `for (struct S {}; 0; ) {}`. However, this is valid in C23, so this patch changes the error to a compatibilty warning and also allows this as an extension in earlier language modes. This also matches GCC’s behaviour.
2025-02-19[Clang] [Sema] Combine fallout warnings to just one warning (#127546)foxtran1-2/+4
This merges several falloff and noreturn-related warnings and removes unused diagnostic arguments. Changes: - `warn_maybe_falloff_nonvoid_function` and `warn_falloff_nonvoid_function`, `warn_maybe_falloff_nonvoid_coroutine` and `warn_falloff_nonvoid_coroutine`, `warn_maybe_falloff_nonvoid_lambda` and `warn_falloff_nonvoid_lambda` were combined into `warn_falloff_nonvoid`, - `err_maybe_falloff_nonvoid_block` and `err_falloff_nonvoid_block` were combined into `err_falloff_nonvoid` - `err_noreturn_block_has_return_expr` and `err_noreturn_lambda_has_return_expr` were merged into `err_noreturn_has_return_expr` with the same semantics as `warn_falloff_nonvoid` or `err_falloff_nonvoid`. - Removed some diagnostic args that weren’t being used by the diagnostics.
2025-02-18[Clang] Warn about `[[noreturn]]` on coroutines (#127623)nerix1-1/+1
Declaring a coroutine `[[noreturn]]` doesn't make sense, because it will always return its handle. Clang previously crashed when trying to warn about this (diagnostic ID was 0). Fixes #127327.
2025-01-29[Clang][P1061] Add stuctured binding packs (#121417)Jason Rice1-2/+4
This is an implementation of P1061 Structure Bindings Introduce a Pack without the ability to use packs outside of templates. There is a couple of ways the AST could have been sliced so let me know what you think. The only part of this change that I am unsure of is the serialization/deserialization stuff. I followed the implementation of other Exprs, but I do not really know how it is tested. Thank you for your time considering this. --------- Co-authored-by: Yanzuo Liu <zwuis@outlook.com>
2025-01-28[clang][SME] Emit error for OpenMP captured regions in SME functions (#124590)Benjamin Maxwell1-0/+21
Currently, these generate incorrect code, as streaming/SME attributes are not propagated to the outlined function. As we've yet to work on mixing OpenMP and streaming functions (and determine how they should interact with OpenMP's runtime), we think it is best to disallow this for now.
2025-01-07[OpenACC] Initial sema implementation of 'update' constructerichkeane1-0/+46
This executable construct has a larger list of clauses than some of the others, plus has some additional restrictions. This patch implements the AST node, plus the 'cannot be the body of a if, while, do, switch, or label' statement restriction. Future patches will handle the rest of the restrictions, which are based on clauses.
2024-12-18[Clang] Implement CWG2813: Class member access with prvalues (#120223)cor3ntin1-46/+71
This is a rebase of #95112 with my own feedback apply as @MitalAshok has been inactive for a while. It's fairly important this makes clang 20 as it is a blocker for #107451 --- [CWG2813](https://cplusplus.github.io/CWG/issues/2813.html) prvalue.member_fn(expression-list) now will not materialize a temporary for prvalue if member_fn is an explicit object member function, and prvalue will bind directly to the object parameter. The E1 in E1.static_member is now a discarded-value expression, so if E1 was a call to a [[nodiscard]] function, there will now be a warning. This also affects C++98 with [[gnu::warn_unused_result]] functions. This should not affect C where TemporaryMaterializationConversion is a no-op. Closes #100314 Fixes #100341 --------- Co-authored-by: Mital Ashok <mital@mitalashok.co.uk>
2024-11-27[Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref ↵Bill Wendling1-0/+2
(#116719) Implement the sema checks with a placeholder. We then check for that placeholder in all of the places we care to emit a diagnostic. Fixes: #115520
2024-11-19[Clang] Improve diagnostic on `[[nodiscard]]` attribute (#112521)Yihe Li1-17/+30
A follow-up to #112289. When diagnosing an unused return value, if the diagnostic is triggered by an attribute attached to a type, the type name is now included in the diagnostic. --------- Co-authored-by: Sirraide <aeternalmail@gmail.com>
2024-11-16[Sema] Remove unused includes (NFC) (#116461)Kazu Hirata1-4/+0
Identified with misc-include-cleaner.
2024-11-15[Clang] [NFC] Refactor AST visitors in Sema and the static analyser to use ↵Sirraide1-5/+5
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-24[clang] Use {} instead of std::nullopt to initialize empty ArrayRef (#109399)Jay Foad1-1/+1
Follow up to #109133.
2024-09-23[clang] Lifetime of locals must end before musttail call (#109255)Oliver Stannard1-0/+10
The lifetimes of local variables and function parameters must end before the call to a [[clang::musttail]] function, instead of before the return, because we will not have a stack frame to hold them when doing the call. This documents this limitation, and adds diagnostics to warn about some code which is invalid because of it.
2024-08-29[NFC][Sema] Move `Sema::AssignmentAction` into its own scoped enum (#106453)Dan Liew1-1/+2
The primary motivation behind this is to allow the enum type to be referred to earlier in the Sema.h file which is needed for #106321. It was requested in #106321 that a scoped enum be used (rather than moving the enum declaration earlier in the Sema class declaration). Unfortunately doing this creates a lot of churn as all use sites of the enum constants had to be changed. Appologies to all downstream forks in advanced. Note the AA_ prefix has been dropped from the enum value names as they are now redundant.
2024-08-18[Clang] warn on discarded [[nodiscard]] function results after casting in C ↵Oleksandr T.1-1/+2
(#104677) Fixes #104391
2024-08-02Surface error for plain return statement in coroutine earlier (#100985)ivanaivanovska1-0/+10
When a plain return statement was used in a coroutine, the error "return statement not allowed in coroutine" was surfaced too late (e.g. after other errors in the return statement). Surfacing it earlier now, to make the issue more obvious.
2024-07-01[clang][NFC] Move documentation of `Sema` functions into `Sema.h`Vlad Serebrennikov1-74/+0
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-06-21[Clang] skip alignment checks on incomplete types to avoid an assertion ↵Oleksandr T1-1/+1
failure while parsing lambda used as default argument (#94542) Fixes #93512
2024-06-11[clang] Replace X && isa<Y>(X) with isa_and_nonnull<Y>(X). NFC (#94987)Pavel Samolysov1-1/+1
This addresses a clang-tidy suggestion.
2024-05-13[clang] Introduce `SemaObjC` (#89086)Vlad Serebrennikov1-303/+4
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-16[clang] Introduce `SemaOpenMP` (#88642)Vlad Serebrennikov1-2/+4
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-13[clang] Introduce `SemaCUDA` (#88559)Vlad Serebrennikov1-2/+3
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-1/+2
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-11[NFC][Clang] Improve const correctness for IdentifierInfo (#79365)Bill Wendling1-5/+3
The IdentifierInfo isn't typically modified. Use 'const' wherever possible.
2024-03-01[OpenACC] Implement no throw out of Compute constructerichkeane1-2/+2
Exception handling SHOULD be possible depending on codegen (and if not, we can make it trap and add a warning when we make that decision), but throwing out of a compute construct is ill formed. This patch adds an error for a 'throw' that isn't in a 'try' scope. This error is imperfect as it won't diagnose a 'throw' that escapes its 'try', or one in a separate function, but it catches the obvious mistakes. The other cases will need to be handled as runtime failures.
2024-03-01[OpenACC] Implement Duffs-Device restriction for Compute Constructs (#83460)Erich Keane1-0/+14
Like the last few patches, branching in/out of a compute construct is not valid. This patch implements checking to ensure that a 'case' or 'default' statement cannot jump into a Compute Construct (in the style of a duff's device!).
2024-02-29[OpenACC] Implement Compute Construct 'goto' in/out logic (#83326)Erich Keane1-0/+16
Compute Constructs do not permit jumping in/out of them, so this patch implements this for 'goto' as a followup to the other patches that have done the same thing. It does this by modifying the JumpDiagnostics to work with this, plus setting the function to needing jump diagnostics if we discover a goto or label inside of a Compute Construct.
2024-02-26[OpenACC] Implement 'return' branch-out of Compute Construct (#82814)Erich Keane1-4/+12
Like with 'break'/'continue', returning out of a compute construct is ill-formed, so this implements the diagnostic. However, unlike the OpenMP implementation of this same diagnostic, OpenACC doesn't have a concept of 'capture region', so this is implemented as just checking the 'scope'.
2024-02-22[OpenACC] Implement 'break' and 'continue' errors for Compute Cnstrcts (#82543)Erich Keane1-0/+22
OpenACC3.3 2.5.4 says: "A program may not branch into or out of a compute construct". While some of this restriction isn't particularly checkable, 'break' and 'continue' are possible and pretty trivial, so this patch implements those limitations. It IS unclear in the case of a 'break' in a 'switch' what should happen (an antagonistic reading of the standard would prevent it from appearing), however we're choosing to special-case the break-in-switch to ensure that this works (albeit, a 'parallel' directive on a 'switch' isn't particularly useful, though permitted). Future implementations of this rule will be in a follow-up patch.
2024-02-12[clang][NFC] Refactor `Sema::TemplateDeductionResult` (#81398)Vlad Serebrennikov1-7/+9
This patch converts `Sema::TemplateDeductionResult` into a scoped enum in namespace scope, making it eligible for forward declaring. This is useful in certain contexts, such as `preferred_type` annotations on bit-fields.
2024-02-11[clang][NFC] Annotate `SemaStmt.cpp` with `preferred_type`Vlad Serebrennikov1-0/+1
This helps debuggers to display values in bit-fields in a more helpful way.