Commit Graph

5758 Commits

Author SHA1 Message Date
Oleksandr T.
05b6c2e4b9 [Clang] fix range calculation for conditionals with throw expressions (#112081)
Fixes #111854

---

The issue arises when `GetExprRange` encounters a `ConditionalOperator`
with a `CXXThrowExpr`

```md
ConditionalOperator 0x1108658e0 'int'
|-CXXBoolLiteralExpr 0x110865878 '_Bool' true
|-CXXThrowExpr 0x1108658a8 'void'
| `-IntegerLiteral 0x110865888 'int' 0
`-IntegerLiteral 0x1108658c0 'int' 0
```


ed3d051782/clang/lib/Sema/SemaChecking.cpp (L9628-L9631)

The current behavior causes the `GetExprRange` to proceed with the throw
expression (`CO->getTrueExpr()`/`void` type)
2024-10-29 10:44:01 +01:00
Sylvestre Ledru
48adfaf3b2 doc: remove trailing whitespaces 2024-10-29 08:05:33 +01:00
Doug Wyatt
034cae42b1 [clang] Add clang/docs/FunctionEffectAnalysis.rst. (#109855)
Follow-on from #99656, which introduces 2nd pass caller/callee analysis
for function effects.

Wrote a new documentation page, derived directly from the RFC posted to
LLVM Discourse earlier this year.

---------

Co-authored-by: Doug Wyatt <dwyatt@apple.com>
Co-authored-by: Sirraide <aeternalmail@gmail.com>
2024-10-28 15:36:37 -07:00
serge-sans-paille
71315698c9 [clang] Warn about memset/memcpy to NonTriviallyCopyable types (#111434)
This implements a warning that's similar to what GCC does in that
context: both memcpy and memset require their first and second operand
to be trivially copyable, let's warn if that's not the case.
2024-10-28 20:40:52 +00:00
Chris Apple
ad5b9441f9 [rtsan][asan] NFC Fix hyperlink to CMake doc (#113931) 2024-10-28 12:25:12 -07:00
Aaron Ballman
af7c58b7ea Remove support for RenderScript (#112916)
See
https://discourse.llvm.org/t/rfc-deprecate-and-eventually-remove-renderscript-support/81284
for the RFC
2024-10-28 12:48:42 -04:00
vabridgers
3d6923dbac RFC: [clang-tidy] [analyzer] Move nondeterministic pointer usage check to tidy (#110471)
This change moves the `alpha.nondeterministic.PointerSorting` and
`alpha.nondeterministic.PointerIteration` static analyzer checkers to a
single `clang-tidy` check. Those checkers were implemented as simple
`clang-tidy` check-like code, wrapped in the static analyzer framework.
The documentation was updated to describe what the checks can and cannot
do, and testing was completed on a broad set of open-source projects.

Co-authored-by: Vince Bridgers <vince.a.bridgers@ericsson.com>
2024-10-28 03:53:36 -05:00
Freddy Ye
5aa1275d03 [X86] Support SM4 EVEX version intrinsics/instructions. (#113402)
Ref.: https://cdrdv2.intel.com/v1/dl/getContent/671368
2024-10-28 10:46:16 +08:00
Chris Apple
a93c952bab [rtsan][NFC] Documentation of suppression flag (#112727) 2024-10-25 14:21:32 -07:00
Dan Gohman
1bc2cd98c5 [WebAssembly] Enable nontrapping-fptoint and bulk-memory by default. (#112049)
We were prepared to enable these features [back in February], but they
got pulled for what appear to be unrelated reasons. So let's have
another try at enabling them!

Another motivation here is that it'd be convenient for the [Lime1
proposal] if "lime1" is close to a subset of "generic" (missing only
for extended-const).

[back in February]:
https://github.com/WebAssembly/tool-conventions/issues/158#issuecomment-1931119512
[Lime1 proposal]: https://github.com/llvm/llvm-project/pull/112035
2024-10-25 13:52:51 -07:00
Boaz Brickner
9043bdbce4 [clang] Output an error when [[lifetimebound]] attribute is applied on a function parameter while the function returns void (#113460)
Fixes: https://github.com/llvm/llvm-project/issues/107556
2024-10-25 15:31:57 +02:00
Benjamin Maxwell
43dda4bbeb [clang][doc] Add release note for changes to -fveclib={ArmPL,SLEEF} (#113673)
Changed in #112580.
2024-10-25 13:08:39 +01:00
Oleksandr T.
b89f09f5cc [Clang] Enhance handling of [[deprecated]] attribute diagnostics for local variables (#113575)
Fixes #90073
2024-10-25 09:40:44 +02:00
Freddy Ye
c4248fa3ed [X86] Support MOVRS and AVX10.2 instructions. (#113274)
Ref.: https://cdrdv2.intel.com/v1/dl/getContent/671368
2024-10-25 09:00:19 +08:00
Endre Fülöp
61a76f58eb [clang][analyzer][doc] Migrate ClangSA www FAQ section (#112831)
The ClangSA documentation lives in RST format, and the FAQ section of
the old webpage is also migrated from HTML with this change.

---------

Co-authored-by: Donát Nagy <donat.nagy@ericsson.com>
2024-10-24 17:37:04 +02:00
Oleksandr T.
61a456bd5a [Clang] prevent assertion failure in value-dependent initializer expressions (#112612)
Fixes #112140

--- 

```
CXXConstructExpr 0x14209e580 'const S':'const struct S' contains-errors 'void (const int &)' list
`-CXXDefaultArgExpr 0x14209e500 'const int' contains-errors
  `-RecoveryExpr 0x14209daf0 'const int' contains-errors
```

This change resolves an issue with evaluating `ArrayFiller` initializers
in _dependent_ contexts, especially when they involve a `RecoveryExpr`.
In certain cases, `ArrayFiller` initializers containing a `RecoveryExpr`
from earlier errors are incorrectly passed to `EvaluateInPlace`, causing
evaluation failures when they are value-dependent.

When this is the case, the initializer is processed through
`EvaluateDependentExpr`, which prevents unnecessary evaluation attempts
and ensures proper handling of value-dependent initializers in
`ArrayFillers`.
2024-10-24 10:34:58 +02:00
Owen Pan
786db636b9 [clang-format] Add KeepFormFeed option (#113268)
Closes #113170.
2024-10-23 19:55:32 -07:00
Congcong Cai
bd6c430dcb [clang codegen] avoid to crash when emit init func for global variable with flexible array init (#113336)
Fixes: #113187
Avoid to create init function since clang does not support global
variable with flexible array init.
It will cause assertion failure later.
2024-10-23 09:21:27 +08:00
Congcong Cai
c0c36aa018 [clang codegen] fix crash emitting __array_rank (#113186)
Fixed: #113044
the type of `ArrayTypeTraitExpr` can be changed, use i32 directly is
incorrect.

---------

Co-authored-by: Eli Friedman <efriedma@quicinc.com>
2024-10-22 17:03:51 +08:00
Younan Zhang
d15559d69d [Clang] Don't assert on substituted-but-yet-expanded packs for nested lambdas (#112896)
Nested lambdas could refer to outer packs that would be expanded by a
larger CXXFoldExpr, in which case that reference could happen to be a
full expression containing intermediate types/expressions, e.g.
SubstTemplateTypeParmPackType/FunctionParmPackExpr. They are designated
as "UnexpandedPack" dependencies but don't introduce new packs anyway.

This also handles a missed case for VarDecls, where the flag of
ContainsUnexpandedPack was not propagated up to the surrounding lambda.

Fixes #112352
2024-10-22 16:51:43 +08:00
Rajveer Singh Bharadwaj
73057349a2 [clang] Allow class with anonymous union member to be const-default-constructible even if a union member has a default member initializer (#95854) (#96301)
Resolves #95854

-- As per https://eel.is/c++draft/dcl.init#general-8.3
2024-10-22 10:31:20 +02:00
BrnBlrg
5e81437f2b [analyzer][doc] Fix typo in "translation unit" in analyzer doc CommandLineUsage.rst (#112966) 2024-10-19 11:06:12 +02:00
cor3ntin
af90e7c516 [Clang] Fix an assertion in expression recovery (#112888)
Explicit object member function calls are not modelled as member calls

Fixes #112559
2024-10-18 15:42:54 +02:00
c8ef
332ac18e31 [clang] constexpr built-in abs function. (#112539)
According to [P0533R9](https://wg21.link/P0533R9), the C++ standard
library functions corresponding to the C macros in `[c.math.abs]` are
now `constexpr`.

To implement this feature in libc++, we must make the built-in abs
function `constexpr`. This patch adds the implementation of a
`constexpr` abs function for the current constant evaluator and the new
bytecode interpreter.

It is important to note that in 2's complement systems, the absolute
value of the most negative value is out of range. In gcc, it will result
in an out-of-range error and will not be evaluated as constants. We
follow the same approach here.
2024-10-18 19:03:50 +08:00
Owen Pan
d989c2410e [clang-format] Add RemoveEmptyLinesInUnwrappedLines option (#112325)
Fixes #111340.
2024-10-17 20:21:42 -07:00
Boaz Brickner
8f25c0bc7d [clang] Fix covariant cv-qualification check to require the override function return type to have the same or less cv-qualification (#112713)
This prevents changing cv-qualification from const to volatile or vice
versa, for example.

https://eel.is/c++draft/class.virtual#8.3

Previously, we checked that the new type is the same or more qualified
to return an error, but the standard requires the new type to be the
same or less qualified and since the cv-qualification is only partially
ordered, we cannot rely on a check on whether it is more qualified to
return an error. Now, we reversed the condition to check whether the old
is at least as qualified, and return an error if it is not.

Also, adjusted the error name and message to clarify the requirement and
added a missing closing parenthesis.

Added tests to cover different use cases for classes with different
qualifications and also refactored them to make them easier to follow:
1. Use override to make sure the function names actually match.
2. Named the function in a more descriptive way to clarify what each use
case is checking.

Fixes: #111742
2024-10-17 16:50:47 +02:00
Mikhnenko Sasha
388d7f1448 Different info in docs in AST methods (#112190)
[Here](6a98c4a160/clang/include/clang/ASTMatchers/ASTMatchers.h (L4188-L4203))
and
[here](6a98c4a160/clang/include/clang/ASTMatchers/ASTMatchers.h (L3679-L3695))
we can see similar code samples and same examples:
```
cxxMemberCallExpr(on(callExpr()))
```

In the first case, it is
[written](6a98c4a160/clang/include/clang/ASTMatchers/ASTMatchers.h (L4201))
that the object must not be matched:
```
/// cxxMemberCallExpr(on(callExpr()))
///   does not match `(g()).m()`, because the parens are not ignored.
```
In the second case, it is
[written](6a98c4a160/clang/include/clang/ASTMatchers/ASTMatchers.h (L3693))
that the object must be matched:
```
/// cxxMemberCallExpr(on(callExpr()))
///   matches `(g()).m()`.
```

I think that parens are ignored
2024-10-17 08:44:45 -04:00
gxlayer
4a2bd78f5b [ARM] Fix -mno-omit-leaf-frame-pointer flag doesn't works on 32-bit ARM (#109628)
The -mno-omit-leaf-frame-pointer flag works on 32-bit ARM architectures
and addresses the bug reported in #108019
2024-10-17 20:25:06 +08:00
Artem Dergachev
5000c688bf [-Wunsafe-buffer-usage] Add user documentation. (#111624)
Originally: https://reviews.llvm.org/D136811
2024-10-16 12:42:49 -07:00
Boaz Brickner
b333edd0d6 [clang] When checking for covariant return types, make sure the pointers or references are to *classes* (#111856)
https://eel.is/c++draft/class.virtual#8.1

This prevents overriding methods with non class return types that have
less cv-qualification.

Fixes: #111742
2024-10-16 16:02:25 +02:00
Balázs Kéri
9df8d8d05c [clang][analyzer] Improve test and documentation in cstring NotNullTerminated checker (#112019)
CStringChecker has a sub-checker alpha.unix.cstring.NotNullTerminated
which checks for invalid objects passed to string functions. The checker
and its name are not exact and more functions could be checked, this
change only adds some tests and improves documentation.
2024-10-16 10:17:34 +02:00
Hans
4ddea298e6 [clang-cl]: Add /std:c++23preview and update _MSVC_LANG for C++23 (#112378)
As discussed in
https://discourse.llvm.org/t/clang-cl-adding-std-c-23preview/82553
2024-10-16 10:06:43 +02:00
Gábor Spaits
48521209aa [Sema]Use tag name lookup for class names (#112166)
This PR would fix #16855 .

The correct lookup to use for class names is Tag name lookup,
because it does not take namespaces into account. The lookup before
does and because of this some valid programs are not accepted.

An example scenario of a valid program being declined is when you have a struct (let's call it `y`) inheriting from another struct with a name `x` but the struct `y` is in a namespace that is also called `x`:
```
struct x
{};

namespace
{
    namespace x
    {
        struct y : x
        {};
    }
}
```

This shall be accepted because: 
```
C++ [class.derived]p2 (wrt lookup in a base-specifier): The lookup for
  // the component name of the type-name or simple-template-id is type-only.
```
2024-10-15 10:19:17 +02:00
awson
37bd788138 [Clang][Sema] Fix templated array size calculation. (#96464)
The [last attempt](https://github.com/llvm/llvm-project/pull/89036) to
fix https://github.com/llvm/llvm-project/issues/41441 has been reverted
immediately.

Here I'm trying the simplest idea I've been able to come with: skip
handling dependent case in `BuildCXXNew`.

The original test (borrowed form
https://github.com/llvm/llvm-project/pull/89036) passes.

Also I've created and added to the tests a minimal repro of the code
https://github.com/llvm/llvm-project/pull/89036 fails on. This
(obviously) also passes.
2024-10-15 07:52:02 +02:00
Younan Zhang
3733b0cff3 [Clang] Fix a DeclContext mismatch when parsing nested lambda parameters (#112177)
When parsing its function parameters, we don't change the CurContext to
the lambda's function declaration. However,
CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures() has not
yet adapted to such behavior when nested lambdas come into play.
Consider the following case,

    struct Foo {};

    template <int, Foo f> struct Arr {};

    constexpr void foo() {
      constexpr Foo F;
      [&]<int I>() {
         [&](Arr<I, F>) {};
       }.template operator()<42>();
    }

As per [basic.def.odr]p5.2, the use of F constitutes an ODR-use. And
per [basic.def.odr]p10, F should be ODR-usable in that interleaving
scope.

We failed to accept the case because the call to tryCaptureVariable()
in getStackIndexOfNearestEnclosingCaptureCapableLambda() suggested
that F is needlessly captureable. That was due to a missed handling
for AfterParameterList in FunctionScopeIndexToStopAt, where it still
presumed DC and LSI matched.

Fixes #47400
Fixes #90896
2024-10-15 12:52:31 +08:00
yabinc
627746581b Reapply "[clang][CodeGen] Zero init unspecified fields in initializers in C" (#109898) (#110051)
This reverts commit d50eaac12f. Also fixes
a bug calculating offsets for bit fields in the original patch.
2024-10-14 16:32:24 -07:00
Artem Belevich
30a06e8022 [CUDA] Add support for CUDA-12.6 and sm_100 (#112028)
This is a copy of #97402(with minor updates), which is now ready to land.

---------

Co-authored-by: Sergey Kozub <skozub@nvidia.com>
2024-10-14 11:51:05 -07:00
Ben Shi
4bf6e831d5 [clang][Driver][AVR] Reject c/c++ compilation for avr1 devices (#111798)
avr-gcc also rejects since these devices has no SRAM.

Fixes https://github.com/llvm/llvm-project/issues/96881
2024-10-14 19:08:58 +08:00
Oleksandr T.
3292ce0867 [Clang] fix overload resolution for object parameters with top-level cv-qualifiers in member functions (#110435)
Fixes #100394
2024-10-12 10:11:36 +02:00
Iuri Chaer
0fba8381d2 [clang-format] Introduce "ReflowComments: IndentOnly" to re-indent comments without breaking internal structure (think Doxygen). (#96804)
* Convert `ReflowComments` from boolean into a new `enum` which can take
on the value `RCS_Never`, `RCS_IndentOnly`, or `RCS_Always`. The first
one is equivalent to the old `false`, the third one is `true`, and the
middle one means that multiline comments should only have their
indentation corrected, which is what Doxygen users will want.
* Preserve backward compatibility while parsing `ReflowComments`.
2024-10-11 19:14:09 -07:00
Eric Astor
9a97a57d9e [clang][frontend] Add support for attribute plugins for statement attributes (#110334)
We already have support for declaration attributes; this is just a matter of extending the plugin infrastructure to cover one more case.
2024-10-11 17:28:44 -04:00
Krystian Stasiowski
2bb3d3a3f3 Reapply "[Clang][Sema] Refactor collection of multi-level template argument lists (#106585, #111173)" (#111852)
This patch reapplies #111173, fixing a bug when instantiating dependent
expressions that name a member template that is later explicitly
specialized for a class specialization that is implicitly instantiated.

The bug is addressed by adding the `hasMemberSpecialization` function,
which return `true` if _any_ redeclaration is a member specialization.
This is then used when determining the instantiation pattern for a
specialization of a template, and when collecting template arguments for
a specialization of a template.
2024-10-11 14:08:06 -04:00
Sirraide
48bda00b28 [Clang] [Sema] Don't crash on unexpanded pack in invalid block literal (#110762)
Consider #109148:
```c++
template <typename ...Ts>
void f() {
    [] {
        (^Ts);
    };
}
```

When we encounter `^Ts`, we try to parse a block and subsequently call
`DiagnoseUnexpandedParameterPack()` (in `ActOnBlockArguments()`), which
sees `Ts` and sets `ContainsUnexpandedParameterPack` to `true` in the
`LambdaScopeInfo` of the enclosing lambda. However, the entire block is
subsequently discarded entirely because it isn’t even syntactically
well-formed. As a result, `ContainsUnexpandedParameterPack` is `true`
despite the lambda’s body no longer containing any unexpanded packs,
which causes an assertion the next time
`DiagnoseUnexpandedParameterPack()` is called.

This pr moves handling of unexpanded parameter packs into
`CapturingScopeInfo` instead so that the same logic is used for both
blocks and lambdas. This fixes this issue since the
`ContainsUnexpandedParameterPack` flag is now part of the block (and
before that, its `CapturingScopeInfo`) and no longer affects the
surrounding lambda directly when the block is parsed. Moreover, this
change makes blocks actually usable with pack expansion.

This fixes #109148.
2024-10-11 20:03:43 +02:00
Alejandro Álvarez Ayllón
bd12729a82 [clang] Ignore inline namespace for hasName (#109147)
Add a new enumeration `SuppressInlineNamespaceMode` to `PrintingPolicy` that
is explicit about how to handle inline namespaces. `SuppressInlineNamespace`
uses that enumeration now instead of a Boolean value.

Specializing a template from an inline namespace should be transparent.
For instance

```
namespace foo {
    inline namespace v1 {
        template<typename A>
        void function(A&);
    }
}

namespace foo {
    template<>
    void function<int>(int&);
}
```

`hasName` should match both declarations of `foo::function`.

Makes the behavior of `matchesNodeFullSlow` and `matchesNodeFullFast`
consistent, fixing an assert inside `HasNameMatcher::matchesNode`.
2024-10-11 09:23:47 -04:00
Erich Keane
c8554e13ee Turn -Wdeprecated-literal-operator on by default (#111027)
It would be nice to see what our users think about this change, as this
is something that WG21/EWG quite wants to fix a handful of questionable
issues with UB. Depending on the outcome of this after being committed,
we might instead suggest EWG undeprecate this, and require a bit of
'magic' from the lexer.

Additionally, this patch makes it so we emit this diagnostic ALSO in
cases where the literal name is reserved. It doesn't make sense to limit
that.

---------

Co-authored-by: Vlad Serebrennikov <serebrennikov.vladislav@gmail.com>
2024-10-11 06:10:03 -07:00
Mikhail Goncharov
efcfa6e711 Revert "Reland: [clang] Finish implementation of P0522 (#111711)"
See discussion in https://github.com/llvm/llvm-project/pull/111711

This reverts commit 6213aa5e58.
2024-10-11 14:47:38 +02:00
Mikhail Goncharov
bdd46cc6b7 Revert "[clang] CWG2398: improve overload resolution backwards compat (#107350)"
See discussion in https://github.com/llvm/llvm-project/pull/111711

This reverts commit 224519b089.
2024-10-11 14:47:21 +02:00
yronglin
774c953cf8 [NFC][clang] Fix typo in ReleaseNotes (#111930)
Fix a typo in ReleaseNotes that introduced by
https://github.com/llvm/llvm-project/pull/86960.

Signed-off-by: yronglin <yronglin777@gmail.com>
2024-10-11 08:15:27 +08:00
yronglin
25d9688c43 [Clang] Extend lifetime of temporaries in mem-default-init for P2718R0 (#86960)
Depends on [CWG1815](https://github.com/llvm/llvm-project/pull/108039).
Fixes https://github.com/llvm/llvm-project/issues/85613.

In [[Clang] Implement P2718R0 "Lifetime extension in range-based for
loops"](https://github.com/llvm/llvm-project/pull/76361), we've not
implement the lifetime extensions for the temporaries which in
`CXXDefaultInitExpr`. As the confirmation in
https://github.com/llvm/llvm-project/issues/85613, we should extend
lifetime for that.

To avoid modifying current CodeGen rules, in a lifetime extension
context, the cleanup of `CXXDefaultInitExpr` was ignored.

---------

Signed-off-by: yronglin <yronglin777@gmail.com>
2024-10-11 00:04:02 +08:00
Oleksandr T.
1fa3c857f0 [Clang] prevent recovery call expression from proceeding with explicit attributes and undeclared templates (#107786)
Fixes #107047
Fixes #49093
2024-10-10 10:02:21 +02:00