[clang] Fix assertion failures involving code completion with delayed default arguments and exception specifications (#203794)
Fixes #200879.
This patch fixes crashes when code completion is invoked immediately
after the declaration of a top-level class containing methods with
default arguments or exception specifications.
Default-argument case: https://godbolt.org/z/4G9nTfnGd
Exception-specification case: https://godbolt.org/z/8frEv8von
When code completion is triggered right after the class body, the
lookahead token is `tok::code_completion` when late parsing begins. The
token is saved to the cached token stream and `ConsumeAnyToken()` is
called to consume it, but `ConsumeAnyToken()` defaults to rejecting
completion tokens, which cuts off parsing. In the default-arguments path
(as reported in #200879), the assertion `Tok.is(tok::equal) && "Default
argument not starting with '='"` is triggered because `cutOffParsing()`
sets the current token to `eof`.
[2 lines not shown]
[M68k][MC] Generate some encoding tests for MOVE (#194269)
# Problem statement
Instruction encoding needs to be solid, as it's one of the foundations
that a target backend is built upon.
It's error-prone work, and tedious to write tests for.
Test coverage for M68k instruction encoding isn't exhaustive, and we've
had bugs in the past where instructions have not been encoded correctly.
# Proposed solution
Using the documentation at https://m680x0.github.io/doc/official-docs it
should be possible to write some scripts to generate encoding tests for
all the instructions.
# Description of this PR
[24 lines not shown]
[analyzer] Implement UseAfterLifetimeEnd checker (#205521)
Implemented the UseAfterLifetimEnd checker which is responsible for detecting lifetime safety violations involving the [[clang::lifetimebound]] annotation. This checker can catch violations in annotated code such as dangling pointer/reference bound to local variables that go out of scope. This checker is one of the reporting checkers that depend on the LifetimeModeling checker #205951. To detect dangling sources the checker queries the state at function exit points through the checkEndFunction callback. This checker does not handle lifetime issues where the code is unannotated.
Detailed work history of this checker can be found here: #200145
Co-authored-by: Balázs Benics <benicsbalazs at gmail.com>
[clang][Driver] Include stdc-predef.h by default on musl
Match GCC behavior for musl-based Linux targets by implicitly passing
`-include stdc-predef.h` for non-freestanding compilations.
Unlike glibc, musl does not arrange for this header to be included through
its normal system headers. As a result, Clang may miss predefined C macros
provided by musl's stdc-predef.h unless users include it manually, while the
same code works with GCC.
Add Driver tests covering musl, non-musl, freestanding, preprocessed input,
missing-header diagnostics, and actual macro visibility.
This patch is based on: https://reviews.llvm.org/D137043 and
slightly tweaks it, as the code has drifted since 2023 when
that was authored.
Co-authored-by: Tao Liang <Origami404 at foxmail.com>
Co-authored-by: YingChi Long <me at inclyc.cn>
[clang] Add test for CWG3129 (#206335)
Adds a test for [CWG3129](https://wg21.link/CWG3129) "Clarify which floating-point-literals are valid".
Clang has supported floating-point literals with overly tiny or huge
exponents since 3.0, with only a warning emitted.
[OpenMP][Clang] Fix parsing of num_teams lower-bound modifier (#205700)
PR #180608 added parsing for the `lower-bound` modifier in the
`num_teams` clause. However, the lower bound expression is handled by
adding it to the first position of the clause's varlist, which is the
list that holds the number of teams for each dimension when `ompx_bare`
is specified. Given that the interpretation of the varlist depends on
its length, the following `ompx_bare` cases are broken:
- `#pragma omp target teams ompx_bare num_teams(11,10)` is interpreted
as a lower-bound and upper-bound, triggering the error "_lower bound is
greater than upper bound in 'num_teams' clause_".
- `#pragma omp target teams ompx_bare num_teams(1,2)` is interpreted as
`num_teams(1:2)` when printing the AST.
This commit fixes the collision by storing the lower bound separated from
the list of upper-bounds. This change is necessary for landing the
upcoming support for multidimensional team spaces (OpenMP 6.1) through
the `dims` modifier.
[VPlan] Support SRem in getSCEVExprForVPValue. (#206361)
Extend vputils::getSCEVExprForVPValue to construct SCEV expressions for
SRem recipes. A SRem of non-negative operands is equivalent to URem.
Enables SCEV-based no-alias reasoning for stores derived from SRem GEPs.
[llubi] Treat `llvm.experimental.noalias.scope.decl` as a noop (#206357)
The noalias support is still work in progress:
https://github.com/llvm/llvm-project/pull/195808
`llvm.experimental.noalias.scope.decl` is emitted by the inliner. We may
need more time to clarify the semantics.
This patch treats the intrinsic as a noop to avoid crashes (metadata
arguments are not supported before this patch).
[InstCombine] Create new instructions instead of in-place operand replacement (#115988)
Fixes https://github.com/llvm/llvm-project/issues/115890.
Currently it doesn't affect final codegen. But we may suffer from this
problem when we utilize these attributes for further optimization (e.g.,
https://github.com/llvm/llvm-project/pull/111284). This test case is
reduced from a csmith-generated C program. And I believe this problem
also exists in real-world programs.
[SmallPtrSet] Optimize Grow and inline FindBucketFor. NFC (#206304)
During rehashing every key is known absent, so skip the equal-key
comparison.
DenseMap got a similar optimization in #200595
FindBucketFor is then only used by insert_imp_big; inline its probe loop
there. The loop takes 7 inst instead of 9 in the clang-generated
assembly after removing the two `LLVM_LIKELY`.
[LV] Add test with pointer based on SRem expression (NFC). (#206344)
Add a test with loads and stores with pointers based on a signed
remainder (srem) of a non-negative induction variable, mirroring the
existing urem test.
[SLP][NFC] Avoid undef usage in odd_store.ll (#206333)
Replace `ret i32 undef` with void return type to avoid CI undef
deprecator failures.
For this PR: https://github.com/llvm/llvm-project/pull/206259
[clang] builtins for atomicrmw fminmax/_num (#187139)
Adds compiler builtins for `atomicrmw`: `fminimum`, `fmaximum`,
`fminimum_num`, `fmaximum_num`.
These will be used by the corresponding libc++ atomic apis (see #186716).