aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema
AgeCommit message (Collapse)AuthorFilesLines
12 hours[OpenACC] Fix checking of sub-expressions in cacheerichkeane1-4/+12
Running an external test suite (UDel) showed that our expression comparison for the 'cache' rule checking was overly strict in the presence of irrelevant parens/casts/etc. This patch ensures we skip them when checking. This also changes the diagnostic to say 'sub-expression' instead of variable, which is more correct.
19 hours[clang] Fix crash when diagnosing unsupported attributes (#150333)Benjamin Maxwell1-1/+2
In #141305, the attribute argument was (unintentionally) removed from the diagnostic emission. Fixes #150237
20 hours[Clang] Fix a partial ordering bug involving CTAD injected template ↵Younan Zhang1-3/+18
arguments (#149782) The synthesized deduction guides use injected template arguments for distinguishment of explicit and implicit deduction guides. In partial ordering, we may substitute into these injected types when checking consistency. Properly substituting them needs the instantiated class template specializations which isn't the case at that point. So instead, we check their template specialization types. No release note because I think we want a backport, after baking it for a couple of days. Fixes https://github.com/llvm/llvm-project/issues/134613
21 hours[Clang] Suppress deprecated field warnings in implicit functions definitions ↵Shashi Shankar1-0/+6
(#147400) Do not warn on deprecated member used in an implicit definition (such as a defaulted special member function). Co-authored-by: Corentin Jabot <corentinjabot@gmail.com> Fixes #147293
27 hours[clang] Avoid inheriting [[noreturn]] in explicit function template ↵Samarth Narang2-0/+15
specializations (#150003) This patch fixes incorrect behavior in Clang where [[noreturn]] (either spelled or inferred) was being inherited by explicit specializations of function templates or member function templates, even when those specializations returned normally. Follow up on https://github.com/llvm/llvm-project/pull/145166
31 hours[clang][Sema][NFC] Fixed incorrect assert messages in SemaOpenMP (#150305)David Pagan1-9/+9
34 hours[clang][OpenMP] In 6.0, can omit length in array section (#148048)David Pagan1-1/+1
In OpenMP 6.0 specification, section 5.2.5 Array Sections, page 166, lines 28-28: When the length is absent and the size of the dimension is not known, the array section is an assumed-size array. Testing - Updated LIT test - check-all - OpenMP_VV (formerly sollve) test case tests/6.0/target/test_target_assumed_array_size.c
35 hours[OpenMP 6.0] Allow only byref arguments with `need_device_addr` modifier on ↵Fazlay Rabbi1-0/+17
`adjust_args` clause (#149586) If the need_device_addr adjust-op modifier is present, each list item that appears in the clause must refer to an argument in the declaration of the function variant that has a reference type. Reference: OpenMP 6.0 [Sec 9.6.2, page 332, line 31-33, adjust_args clause, Restrictions]
37 hours[clang-repl] Always clean up scope and context for TopLevelStmtDecl (#150215)Devajith1-1/+2
This fixes an issue introduced by https://github.com/llvm/llvm-project/pull/84150, where failing to pop compound scope, function scope info, and decl context after a failed statement could lead to an inconsistent internal state.
40 hours[Clang] Fix a crash on invalid concept (#150186)Corentin Jabot1-0/+3
Fixes #149986
2 days[API Notes] Attach API notes to forward declarations of tags (#149951)Doug Gregor1-0/+4
Forward declarations can still have useful API notes applied to them. When the use of the tag is not a definition, apply the API notes immediately. Fixes rdar://156288588.
2 days[Clang] Add elementwise maximumnum/minimumnum builtin functions (#149775)Wenju He1-0/+2
Addresses https://github.com/llvm/llvm-project/issues/112164. minimumnum and maximumnum intrinsics were added in 5bf81e53dbea. The new built-ins can be used for implementing OpenCL math function fmax and fmin in #128506.
2 days[LifetimeSafety] Add language option for experimental lifetime safety (#149592)Utkarsh Saxena1-2/+1
Add a language option flag for experimental lifetime safety analysis in C++. This change provides a language option to control the experimental lifetime safety analysis feature, making it more explicit and easier to enable/disable. Previously, the feature was controlled indirectly through a diagnostic warning flag, which we do not want to accidentally enable with `-Weverything` (atm)! ### Changes: - Added a new language option `EnableLifetimeSafety` in `LangOptions.def` for experimental lifetime safety analysis in C++ - Added corresponding driver options `-fexperimental-lifetime-safety` and `-fno-experimental-lifetime-safety` in `Options.td` - Modified `AnalysisBasedWarnings.cpp` to use the new language option flag instead of checking if a specific diagnostic is ignored - Updated a test case to use the new flag instead of relying on the warning flag alone
3 daysReapply "[LifetimeSafety] Revamp test suite using unittests (#149158)"Utkarsh Saxena1-2/+2
This reverts commit 54b50681ca0fd1c0c6ddb059c88981a45e2f1b19.
3 days[NFC][Clang][FMV] Refactor sema checking of target_version/clones ↵Alexandros Lamprineas4-254/+298
attributes. (#149067) Sema currently has checkTargetVersionAttr and checkTargetClonesAttrString to diagnose the said attributes. However the code tries to handle all of AArch64, RISC-V and X86 targets at once which is hard to maintain, therefore I am splitting these functions. Unfortunately I could not use polymorphism because all of Sema, SemaARM, SemaRISCV and SemaX86 inherit from SemaBase. The Sema instance itself contains instances of every other target specific Sema.
3 daysRevert "[LifetimeSafety] Revamp test suite using unittests (#149158)"Utkarsh Saxena1-2/+2
This reverts commit 688ea048affe8e79221ea1a8c376bcf20ef8f3bb.
3 days[LifetimeSafety] Revamp test suite using unittests (#149158)Utkarsh Saxena1-2/+2
Refactor the Lifetime Safety Analysis infrastructure to support unit testing. - Created a public API class `LifetimeSafetyAnalysis` that encapsulates the analysis functionality - Added support for test points via a special `TestPointFact` that can be used to mark specific program points - Added unit tests that verify loan propagation in various code patterns
3 days[clang] [Sema] Check argument range for prefetchi* intrinsics (#149745)Timothy Herchen1-0/+5
Fixes https://github.com/llvm/llvm-project/issues/144857 . I can create a test if desired, but I think the fix is trivial enough. <img width="805" height="105" alt="image" src="https://github.com/user-attachments/assets/aaee8e5f-6e65-4f04-b8b9-e4ae1434d958" />
6 daysReland [Clang] Make the SizeType, SignedSizeType and PtrdiffType be named ↵YexuanXiao4-6/+17
sugar types (#149613) The checks for the 'z' and 't' format specifiers added in the original PR #143653 had some issues and were overly strict, causing some build failures and were consequently reverted at https://github.com/llvm/llvm-project/commit/4c85bf2fe8042c855c9dd5be4b02191e9d071ffd. In the latest commit https://github.com/llvm/llvm-project/pull/149613/commits/27c58629ec76a703fde9c0b99b170573170b4a7a, I relaxed the checks for the 'z' and 't' format specifiers, so warnings are now only issued when they are used with mismatched types. The original intent of these checks was to diagnose code that assumes the underlying type of `size_t` is `unsigned` or `unsigned long`, for example: ```c printf("%zu", 1ul); // Not portable, but not an error when size_t is unsigned long ``` However, it produced a significant number of false positives. This was partly because Clang does not treat the `typedef` `size_t` and `__size_t` as having a common "sugar" type, and partly because a large amount of existing code either assumes `unsigned` (or `unsigned long`) is `size_t`, or they define the equivalent of size_t in their own way (such as sanitizer_internal_defs.h).https://github.com/llvm/llvm-project/blob/2e67dcfdcd023df2f06e0823eeea23990ce41534/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h#L203
7 days[Clang] Do not assume a perfect match is a better match than a non-template ↵Corentin Jabot1-43/+6
non-perfect match (#149504) This fixes a regression introduced by the "perfect match" overload resolution mechanism introduced in 8c5a307. [This does regress the performance noticeably (-0.7% for a stage 2 build)](https://llvm-compile-time-tracker.com/compare.php?from=42d2ae1034b287eb60563c370dbf52c59b66db20&to=82303bbc3e003c937ded498ac9f94f49a3fc3d90&stat=instructions:u), however, the original patch had a +4% performance impact, so we are only losing some of the gain, and this has the benefit of being correct and more robust. Fixes #147374
7 days[Clang] Ensure correct parameters are in the scope for constraint ↵Younan Zhang1-0/+5
equivalence checking (#149264) This is another case where untransformed constraint expressions led to inconsistent transforms. We did fix some of those issues by looking at parent scopes, however the parent instantiation scope is not always available because we could also reach here after the parents get instantiated. Fixes #146614
7 daysRevert "[Clang] Make the SizeType, SignedSizeType and PtrdiffType be named ↵Kazu Hirata4-17/+6
sugar types instead of built-in types (#143653)" This reverts commit c27e283cfbca2bd22f34592430e98ee76ed60ad8. A builbot failure has been reported: https://lab.llvm.org/buildbot/#/builders/186/builds/10819/steps/10/logs/stdio I'm also getting a large number of warnings related to %zu and %zx.
7 days[Clang] Make the SizeType, SignedSizeType and PtrdiffType be named sugar ↵YexuanXiao4-6/+17
types instead of built-in types (#143653) Including the results of `sizeof`, `sizeof...`, `__datasizeof`, `__alignof`, `_Alignof`, `alignof`, `_Countof`, `size_t` literals, and signed `size_t` literals, the results of pointer-pointer subtraction and checks for standard library functions (and their calls). The goal is to enable clang and downstream tools such as clangd and clang-tidy to provide more portable hints and diagnostics. The previous discussion can be found at #136542. This PR implements this feature by introducing a new subtype of `Type` called `PredefinedSugarType`, which was considered appropriate in discussions. I tried to keep `PredefinedSugarType` simple enough yet not limited to `size_t` and `ptrdiff_t` so that it can be used for other purposes. `PredefinedSugarType` wraps a canonical `Type` and provides a name, conceptually similar to a compiler internal `TypedefType` but without depending on a `TypedefDecl` or a source file. Additionally, checks for the `z` and `t` format specifiers in format strings for `scanf` and `printf` were added. It will precisely match expressions using `typedef`s or built-in expressions. The affected tests indicates that it works very well. Several code require that `SizeType` is canonical, so I kept `SizeType` to its canonical form. The failed tests in CI are allowed to fail. See the [comment](https://github.com/llvm/llvm-project/pull/135386#issuecomment-3049426611) in another PR #135386.
7 days[Clang][AST][NFC] Introduce `NamespaceBaseDecl` (#149123)Yanzuo Liu7-42/+12
Add `NamespaceBaseDecl` as common base class of `NamespaceDecl` and `NamespaceAliasDecl`. This simplifies `NestedNameSpecifier` a bit. Co-authored-by: Matheus Izvekov <mizvekov@gmail.com>
7 days[Sema] Remove unnecessary casts (NFC) (#149340)Kazu Hirata1-3/+3
getArrayIndex(), getArrayRangeStart(), and getArrayRangeEnd() already return Expr *.
8 days[Sema] Use llvm::all_of (NFC) (#149256)Kazu Hirata1-2/+1
We can pass a range to llvm::all_of.
8 days[Sema] Remove unnecessary casts (NFC) (#149253)Kazu Hirata1-5/+3
getParam already returns NamedDecl *.
8 daysRevert "[Clang] Do not treat Foo -> const Foo conversion sequences as ↵Corentin Jabot1-13/+1
perfect" (#149272) Reverts llvm/llvm-project#148613 Considering object argument conversion qualifications perfect leads to situations where we prefer a non-template const qualified function over a non-qualified template function, which is very wrong indeed. I explored solutions to work around that, but instead, we might want to go the GCC road and prefer the friend overload in the #147374 example, as this seems a lot more consistent and reliable
8 days[HLSL][DXIL] Implement `refract` intrinsic (#147342)raoanag1-0/+80
- [x] Implement refract using HLSL source in hlsl_intrinsics.h - [x] Implement the refract SPIR-V target built-in in clang/include/clang/Basic/BuiltinsSPIRV.td - [x] Add sema checks for refract to CheckSPIRVBuiltinFunctionCall in clang/lib/Sema/SemaSPIRV.cpp - [x] Add codegen for spv refract to EmitSPIRVBuiltinExpr in CGBuiltin.cpp - [x] Add codegen tests to clang/test/CodeGenHLSL/builtins/refract.hlsl - [x] Add spv codegen test to clang/test/CodeGenSPIRV/Builtins/refract.c - [x] Add sema tests to clang/test/SemaHLSL/BuiltIns/refract-errors.hlsl - [x] Add spv sema tests to clang/test/SemaSPIRV/BuiltIns/refract-errors.c - [x] Create the int_spv_refract intrinsic in IntrinsicsSPIRV.td - [x] In SPIRVInstructionSelector.cpp create the refract lowering and map it to int_spv_refract in SPIRVInstructionSelector::selectIntrinsic. - [x] Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/refract.ll - [x] Check for what OpenCL support is needed. Resolves https://github.com/llvm/llvm-project/issues/99153
8 days[OpenACC][Sema] Implement warning for non-effective 'private' (#149004)Erich Keane1-5/+65
A 'private' variable reference needs to have a default constructor and a destructor, else we cannot properly emit them in codegen. This patch adds a warning-as-default-error to diagnose this. We'll have to do something similar for firstprivate/reduction, however it isn't clear whether we could skip the check for default-constructor for those two (they still need a destructor!). Depending on how we intend to create them (and we probably have to figure this out?), we could either require JUST a copy-constructor (then make the init section just the alloca, and the copy-ctor be the 'copy' section), OR they require a default-constructor + copy-assignment.
9 days[Clang] FunctionEffects: Make a separate diagnostic group for ↵Doug Wyatt1-1/+9
redeclarations/overrides where effects are implicit. (#148690) The current function effect diagnostics include these behaviors: When you declare a function `nonblocking` (typically in a header) and then omit the attribute on the implementation (or any other redeclaration), Clang warns: attribute 'nonblocking' on function does not match previous declaration. But if a `nonblocking` function is a C++ virtual method, then overrides are implicitly nonblocking; the attribute doesn't need to be explicitly stated. These behaviors are arguably inconsistent -- and also, both, more pedantic than the rest of the function effect diagnostics. This PR accomplishes two things: - Separates the diagnostic on a redeclaration into a new group, `-Wfunction-effect-redeclarations`, so it can be disabled independently. - Adds a second diagnostic to this new group, for the case of an override method missing the attribute. (This helps in a situation where I'm trying to add `nonblocking` via a macro that does other things and I want to know that the macro is missing on an override declaration.) --------- Co-authored-by: Doug Wyatt <dwyatt@apple.com> Co-authored-by: Sirraide <aeternalmail@gmail.com>
9 days[clang][amdgpu] Add builtin for struct buffer lds load (#148950)zGoldthorpe1-0/+1
This is essentially just a revision of #137678 which only exposes a builtin for the intrinsic `llvm.amdgcn.struct.ptr.buffer.load.lds`, which expects an `__amdgpu_buffer_rsrc_t` rather than a `v4i32` as its first argument. The reason for excluding the other intrinsics exposed by the cited PR is because the intrinsics taking a `v4i32` are legacy and should be deprecated.
9 daysThread Safety Analysis: Fix pointer handling of variables with deprecated ↵Marco Elver1-5/+20
attributes (#148974) de10e44b6fe7 ("Thread Safety Analysis: Support warning on passing/returning pointers to guarded variables") added checks for passing pointer to guarded variables. While new features do not necessarily need to support the deprecated attributes (`guarded_var`, and `pt_guarded_var`), we need to ensure that such features do not cause the compiler to crash. As such, code such as this: struct { int v __attribute__((guarded_var)); } p; int *g() { return &p.v; // handleNoMutexHeld() with POK_ReturnPointer } Would crash in debug builds with the assertion in handleNoMutexHeld() triggering. The assertion is meant to capture the fact that this helper should only be used for warnings on variables (which the deprecated attributes only applied to). To fix, the function handleNoMutexHeld() should handle all POK cases that apply to variables explicitly, and produce a best-effort warning. We refrain from introducing new warnings to avoid unnecessary code bloat for deprecated features. Fixes: https://github.com/llvm/llvm-project/issues/140330
9 days[Sema] Remove unnecessary casts (NFC) (#148871)Kazu Hirata4-4/+4
getArgAsExpr already returns Expr *.
9 days[NFC] Remove getDefaultCallingConvention IsBuiltin (#145904)Harald van Dijk3-4/+5
ASTContext::getDefaultCallingConvention() was documented as returning "the default calling convention for the current target", but did not do this, and was never intended to do this, it has always been controlled by command-line options to deviate from the target default. This commit changes ASTContext::getDefaultCallingConvention() to reflect the fact that it returns the context's default calling convention, not the target's default calling convention. The IsBuiltin parameter, which was used to return the target's default calling convention rather than the context's, is removed in favor of getTargetInfo().getDefaultCallingConv() which is more explicit of the intent.
9 days[NFC][SemaHLSL] Fix typo causing float to double conversion (#148941)Finn Plummer1-1/+1
- it was noted, [here](https://github.com/llvm/llvm-project/pull/145795#discussion_r2208118547), that by accidently not specifying this explicitly as a float it will cause a build warning on MSVC - this commit resolves this by explicitly specifying it as a float
9 days[C++] Fix a failed assertion with nullability checking (#148881)Aaron Ballman1-3/+8
This fixes a failed assertion with an operator call expression which comes from a macro expansion when performing analysis for nullability attributes. Fixes #138371
10 days[Clang] Remove explicit object from non member function. (#148807)Corentin Jabot1-1/+3
To avoid crashing later (as we assume only member functions can have explicit object parameters) Fixes #113185
10 days[Clang] Do not treat Foo -> const Foo conversion sequences as perfect (#148613)Corentin Jabot1-1/+13
For implicit object arguments. This fixes a regression introduced by the "perfect match" overload resolution mechanism introduced in 8c5a307. Note that GCC allows the ambiguity between a const and non-const candidate to be resolved. But this patch focuses on restoring the Clang 20 behavior, and to fix the cases which we did resolve incorrectly. Fixes #147374
10 days[Analysis] Avoid some warnings about exit from noreturn function (#144408)Serge Pavlov1-0/+150
Compiler sometimes issues warnings on exit from 'noreturn' functions, in the code like: [[noreturn]] extern void nonreturnable(); void (*func_ptr)(); [[noreturn]] void foo() { func_ptr = nonreturnable; (*func_ptr)(); } where exit cannot take place because the function pointer is actually a pointer to noreturn function. This change introduces small data analysis that can remove some of the warnings in the cases when compiler can prove that the set of reaching definitions consists of noreturn functions only.
10 days[Sema] Remove unnecessary casts (NFC) (#148762)Kazu Hirata1-2/+2
getAsmLabel() already returns Expr *.
10 days[clang][ObjC][PAC] Add ptrauth protections to objective-c (#147899)Oliver Hunt2-0/+17
This PR introduces the use of pointer authentication to objective-c[++]. This includes: * __ptrauth qualifier support for ivars * protection of isa and super fields * protection of SEL typed ivars * protection of class_ro_t data * protection of methodlist pointers and content
10 days[clang] Update diagnostics and documentation for type aware allocators (#148576)Oliver Hunt1-6/+2
Alas reflection pushed p2719 out of C++26, so this PR changes the diagnostics to reflect that for now type aware allocation is functionally a clang extension.
10 days[clang] Add -Wuninitialized-const-pointer (#148337)Igor Kudrin1-4/+16
This option is similar to -Wuninitialized-const-reference, but diagnoses the passing of an uninitialized value via a const pointer, like in the following code: ``` void foo(const int *); void test() { int v; foo(&v); } ``` This is an extract from #147221 as suggested in [this comment](https://github.com/llvm/llvm-project/pull/147221#discussion_r2190998730).
10 days[clang] Fix suppressing diagnostics for uninitialized variables (#148336)Igor Kudrin1-40/+48
When one kind of diagnostics is disabled, this should not preclude other diagnostics from displaying, even if they have lower priority. For example, this should print a warning about passing an uninitialized variable as a const reference: ``` > cat test.cpp void foo(const int &); int f(bool a) { int v; if (a) { foo(v); v = 5; } return v; } > clang test.cpp -fsyntax-only -Wuninitialized -Wno-sometimes-uninitialized ```
11 days[clang] Build argument string for clang::warn_unused_result (#148090)zebullax1-21/+30
Preserve the argument-clause for `warn-unused-result` when under clang:: scope. We are not touching gnu:: scope for now as it's an error for GCC to have that string. Personally I think it would be ok to relax it here too as we are not introducing breakage to currently passing code, but feedback is to go slowly about it.
11 days[Clang] Do not emit -Wmissing-noreturn when [[noreturn]] is present (#148552)Corentin Jabot1-1/+1
Fix a false positve warning which was introduced by #146234.
11 days[Clang] Consider default template arguments when synthesizing CTAD guides ↵Younan Zhang1-3/+22
(#147675) We copy arguments from different template parameter lists depending on the deducibility of the template parameters. In particular, we may lose the default template argument from the original alias declaration, and this patch helps preserve that. Fixes https://github.com/llvm/llvm-project/issues/133132
11 days[Sema] Remove an unnecessary cast (NFC) (#148531)Kazu Hirata1-2/+1
Dtor is already of CXXDestructorDecl *.
11 days[HLSL][RootSignature] Add basic parameter validations of Root Elements (#145795)Finn Plummer1-1/+92
In this pr we go through and enforce the various bounded parameter values for non-flag values and the valid flag combinations for `RootDescriptor` and `DescriptorRange` flags. For reference of the required checks, please see here: https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-in-sema. - Updates `SemaHLSL` to iterate through `RootElement`s and verify that all non-flag parameters are within their bounds - Updates `SemaHLSL` to iterate through `RootElement`s and verify that all flag parameters are a valid combination - Extends `RootSignature-err.hlsl` with testcases for all invalid specifications - Adds `RootSignature-flags-err.hlsl` with testcase for invalid flag specifications Resolves: https://github.com/llvm/llvm-project/issues/129940