5924 Commits

Author SHA1 Message Date
jijjijj
9f1e9f682d
[C++20][modules] Fix std::initializer_list recognition if it's exported out of a module (#118537)
If the std::initializer_list is exported out of module, its
`DeclContext` is not a namespace as `Sema::isStdInitializerList`
expects, but an `Decl::Kind::Export` and only its parent is a namespace.
So this commit makes `Sema::isStdInitializerList` account for that.

I'm really new to clang so I'm not 100% sure that was the issue, it
seems so and it fixes compilation. Also I probably need to add tests but
I'd like someone to approve the idea first.

Fixes https://github.com/llvm/llvm-project/issues/118218
2024-12-12 09:38:47 +08:00
Younan Zhang
d44518c1cc
[Clang] Don't check incomplete CXXRecordDecl's members when transforming sizeof...(expr) (#119344)
For a FunctionParmPackExpr that is used as the argument of a
sizeof...(pack) expression, we might exercise the logic that checks the
CXXRecordDecl's members regardless of the type being incomplete, when
rebuilding the DeclRefExpr into non-ODR-used forms.

Fixes https://github.com/llvm/llvm-project/issues/81436
2024-12-10 18:37:30 +08:00
Chuanqi Xu
411196b9bb
[C++20] [Modules] Convert '-fexperimental-modules-reduced-bmi' to '-fmodules-reduced-bmi' (#114382)
According to our previous consensus in
https://clang.llvm.org/docs/StandardCPlusPlusModules.html#reduced-bmi,
the reduced BMI will be the default and recommend users to use the new
option.

The `-fexperimental-modules-reduced-bmi ` option is introduced in
https://github.com/llvm/llvm-project/pull/85050 in Mar13 and released in
19.x. And now we are in 20's release cycle. Also I rarely receive issue
reports about reduced BMI. No matter it is due to the quality of reduced
BMI is really good or no one uses it.

This patch literally did the second point in
https://clang.llvm.org/docs/StandardCPlusPlusModules.html#reduced-bmi
2024-12-10 15:18:26 +08:00
ykiko
77a08a73cc
[Clang] Fix wrong call location of DefaultArgExpr (#119212)
Fix https://github.com/llvm/llvm-project/issues/119129.
2024-12-10 14:01:40 +08:00
Carlo Cabrera
511e84ff26
[clang][docs] fix rendering of $-prefixed options (#119249)
This was added in #117573 but the options were not being rendered
correctly due to the missing newline after `::`.
2024-12-10 03:24:04 +08:00
Oleksandr T.
1094641bc0
[Clang] allow usage of placement new operator in [[msvc::constexpr]] context outside of the std namespace (#119153)
Fixes #74924
2024-12-09 18:47:38 +02:00
cor3ntin
6d759f83eb
[Clang] Deleting an incomplete enum type is not an error (#119077)
The changes introduced in #97733 accidentally prevented to delete an
incomplete enum
(the validity of which has been confirmed by CWG2925
    
Fixes #99278
2024-12-09 10:20:16 +01:00
Owen Pan
411df3bb49 [clang-format] Make command lines of dump_format_[style|help].py consistent 2024-12-09 00:56:24 -08:00
Younan Zhang
a4506bb340
[Clang] Recurse into parsing when using pack-indexing as a specifier (#119123)
Pack indexing type that introduces a scope, e.g. `T...[0]::value` would
be annotated as `annot_cxxscope`. This is something we didn't handle in
`ParseCastExpression`, causing it to mistakely fall through to the logic
for `raw_identifier`.

We should recurse into parsing the following specifiers for such cases.

Closes #119072
2024-12-09 09:58:37 +08:00
c8ef
f145ff3f70
[clang] constexpr built-in elementwise add_sat/sub_sat functions. (#119082)
Part of #51787.

This patch adds constexpr support for the built-in elementwise add_sat
and sub_sat functions.
2024-12-09 09:28:12 +08:00
Chris Apple
8843d2b469
[rtsan] Add verify_interceptors flag to docs (#119074) 2024-12-08 09:34:40 -08:00
Owen Pan
eeadd0128d [clang-format] Also check ClangFormat.rst is up to date in docs_updated.test 2024-12-08 01:15:45 -08:00
Amr Hesham
3f458cd9ab
[Clang] Warning as error Array Comparisons from C++26 (#118872)
Starting from C++26 the array comparison warning should converted to an
error.

Fixes: #117859
2024-12-07 18:28:09 +01:00
Chris Apple
342c8db381
[rtsan] NFC: Docs update adding links to Disabling, adding a few ` marks (#119075) 2024-12-07 08:25:08 -08:00
Paul Osmialowski
755519f7f6
[clang][driver] Use $ prefix with config file options to have them added after all of the command line options (#117573)
Currently, if a -l (or -Wl,) flag is added into a config file
(e.g. clang.cfg), it is situated before any object file in the
effective command line. If the library requested by given -l flag is
static, its symbols will not be made visible to any of the object
files provided by the user. Also, the presence of any of the linker
flags in a config file confuses the driver whenever the user invokes
clang without any parameters (see issue #67209).

This patch attempts to solve both of the problems, by allowing a split
of the arguments list into two parts. The head part of the list will
be used as before, but the tail part will be appended after the
command line flags provided by the user and only when it is known
that the linking should occur. The $-prefixed arguments will be added
to the tail part.
2024-12-07 11:18:44 +00:00
cor3ntin
bcf6f84763
Revert "[Clang] Deleting an incomplete enum type is not an error (#118455) (#118980)
This reverts commit 8271195de05742ed7079d7882fbebc2daecbd7e2.
2024-12-07 04:22:47 +01:00
Owen Pan
9a5946cdba [clang-format] Add --directory option to dump_format_help.py 2024-12-05 20:16:09 -08:00
Owen Pan
74d29c6393 [clang-format] Open plurals.txt in read-only mode in dump_format_style.py 2024-12-05 19:25:32 -08:00
Aaron Ballman
91354fb146
[C++20] Destroying delete can cause a type to be noexcept when deleting (#118687)
Given a `noexcept` operator with an operand that calls `delete`, Clang
was not considering whether the selected `operator delete` function was
a destroying delete or not when inspecting whether the deleted object
type has a throwing destructor. Thus, the operator would return `false`
for a type with a potentially throwing destructor even though that
destructor would not be called due to the destroying delete. Clang now
takes the kind of delete operator into consideration.

Fixes #118660
2024-12-05 14:26:33 -05:00
Rashmi Mudduluru
51a5b77b57
[Webkit Checkers] Introduce a Webkit checker for memory unsafe casts (#114606)
This PR introduces a new checker
`[alpha.webkit.MemoryUnsafeCastChecker]` that warns all downcasts from a base type to a derived type.

rdar://137766829
2024-12-05 11:01:27 -08:00
Chris White
d457100a81
[Clang] Fix -Wunused-private-field false negative with defaulted comparison operators (#116871)
Fix -Wunused-private-field incorrectly suppressing warnings for friend
defaulted comparison operators. The warning should only be suppressed
when the defaulted comparison is a class member function.

Fixes #116270
2024-12-05 16:32:48 +01:00
serge-sans-paille
3a8ada67ff
[clang][NFC] Fix miscellaneous typos in release notes 2024-12-05 09:59:57 +01:00
Aiden Grossman
a9a4a83b61
[clang-format] Add test to ensure formatting options docs are updated (#118154)
This patch adds a lit test to clang format to ensure that the
ClangFormatStyleOptions doc page has been updated appropriately. The
test just runs the automatic update script and diffs the outputs to
ensure they are the same.
2024-12-04 23:41:12 -08:00
Florian Hahn
7954a0514b
[Clang] Enable -fpointer-tbaa by default. (#117244)
Support for more precise TBAA metadata has been added a while ago
(behind the -fpointer-tbaa flag). The more precise TBAA metadata allows
treating accesses of different pointer types as no-alias.

This helps to remove more redundant loads and stores in a number of
workloads.

Some highlights on the impact across llvm-test-suite's MultiSource,
SPEC2006 & SPEC2017 include:
 * +2% more NoAlias results for memory accesses
 * +3% more stores removed by DSE,
 * +4% more loops vectorized.

This closes a relatively big gap to GCC, which has been supporting
disambiguating based on pointer types for a long time.
(https://clang.godbolt.org/z/K7Wbhrz4q)

Pointer-TBAA support for pointers to builtin types has been added in
https://github.com/llvm/llvm-project/pull/76612.

Support for user-defined types has been added in
https://github.com/llvm/llvm-project/pull/110569.

There are 2 recent PRs with bug fixes for special cases uncovered during
testing:
 * https://github.com/llvm/llvm-project/pull/116991
 * https://github.com/llvm/llvm-project/pull/116596

PR: https://github.com/llvm/llvm-project/pull/117244
2024-12-04 20:55:18 +00:00
Amr Hesham
7347e5e89a
[Clang] Add '-Warray-compare' flag for C++ below version 20 (#118031)
Currently, we support `-wdeprecated-array-compare` for C++20 or above
and don't report any warning for older versions, this PR supports
`-Warray-compare` for older versions and for GCC compatibility.

Fixes #114770
2024-12-04 19:33:25 +01:00
cor3ntin
8271195de0
[Clang] Deleting an incomplete enum type is not an error (#118455)
The changes introduced in #97733 accidentally prevented to delete an
incomplete enum (the validity of which has been confirmed by CWG2925

Fixes #99278
2024-12-04 15:31:19 +01:00
Younan Zhang
154c7c0bf2
[Clang] Don't add top-level const qualifiers to captured function types (#118050)
This aligns with the logic in `TreeTransform::RebuildQualifiedType()`
where we refrain from adding const qualifiers to function types.
Previously, we seemed to overlook this edge case when copy-capturing a
variable that is of function type within a const-qualified lambda.

This issue also reveals other related problems as in incorrect type
printout and a suspicious implementation in DeduceTemplateArguments. I
decide to leave them in follow-up work.

Fixes #84961
2024-12-04 15:31:15 +08:00
Shilei Tian
68bcba6d7a Revert "[AMDGPU] Use COV6 by default (#118515)"
This reverts commit 410cbe3cf28913cca2fc61b3437306b841d08172 because some
buildbots are not ready yet.
2024-12-03 20:17:06 -05:00
Shilei Tian
410cbe3cf2
[AMDGPU] Use COV6 by default (#118515) 2024-12-03 19:38:35 -05:00
Dan Gohman
35cce408ee
[WebAssembly] Support the new "Lime1" CPU (#112035)
This adds WebAssembly support for the new [Lime1 CPU].

First, this defines some new target features. These are subsets of
existing
features that reflect implementation concerns:

- "call-indirect-overlong" - implied by "reference-types"; just the
overlong
encoding for the `call_indirect` immediate, and not the actual reference
   types.

 - "bulk-memory-opt" - implied by "bulk-memory": just `memory.copy` and
   `memory.fill`, and not the other instructions in the bulk-memory
    proposal.

Next, this defines a new target CPU, "lime1", which enables
mutable-globals,
bulk-memory-opt, multivalue, sign-ext, nontrapping-fptoint,
extended-const,
and call-indirect-overlong. Unlike the default "generic" CPU, "lime1" is
meant
to be frozen, and followed up by "lime2" and so on when new features are
desired.

[Lime1 CPU]:
https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#lime1

---------

Co-authored-by: Heejin Ahn <aheejin@gmail.com>
2024-12-03 16:35:23 -08:00
Congcong Cai
b5b15c1973
[ast matcher][NFC] make dump_ast_matchers.py run in any path (#117942) 2024-12-04 05:21:07 +08:00
Rashmi Mudduluru
fdd09e9de5
[ASTMatchers] AST matcher support for ObjC pointers (#117021)
Add `ObjCInterfaceDecl` to the list of types supported by the `hasType`
and `hasDeclaration` matchers, `ObjCObjectPointerType` to the list of
types supported by `pointee`.
These AST matcher improvements will help the new WebKit checker for
unsafe casts
([https://github.com/llvm/llvm-project/pull/114606](https://github.com/llvm/llvm-project/pull/114606))
match on unsafe Objective-C pointer casts.
2024-12-03 12:26:20 -08:00
Aidan Goldfarb
9791f25807
[clang][sema] Add support and documentation for __has_extension(c_fixed_enum) (#117507)
This PR addresses #116880 

Updated
[LanguageExtensions.rst](https://github.com/llvm/llvm-project/blob/main/clang/docs/LanguageExtensions.rst)
to include support for C++11 enumerations with a fixed underlying type
in C. Included a note that this is only a language extension prior to
C23.

Updated
[Features.def](https://github.com/llvm-mirror/clang/blob/master/include/clang/Basic/Features.def)
to support for `__has_extension(c_fixed_enum)` by added it as a feature
(for C23) and an extension (for <C23).

Updated
[enum.c](https://github.com/llvm/llvm-project/blob/main/clang/test/Sema/enum.c)
to ensure support of C++11 enumerations with a fixed underlying type in
both <C23 and C23, as well as the functionality of
`__has_extension(c_fixed_enum)`.

---

In enum.c, I encountered a warning when testing enumerations with a
fixed underlying type in pre-C23 modes. Specifically, the test produces
the warning: `enumeration types with a fixed underlying type are a C23
extension`. I am unsure if this warning is expected behavior, as
enumerations with a fixed underlying type should behave identically in
pre-C23 and C23 modes. I expected that adding `c_fixed_enum` as an
extension would fix this warning. Feedback on whether this is correct or
requires adjustment would be appreciated.

I was also unsure of the best location for the additions in
`Features.def`, I would appreciate advice on this as well

Note that this is my first PR to LLVM, so please liberally critique it!
2024-12-03 13:39:17 -05:00
Shilei Tian
95a4d30b0d [NFC] Remove trailing white spaces in clang/docs/ReleaseNotes.rst 2024-12-03 12:27:04 -05:00
Jim B
56ab56c857
[clang-format] Add support for .cjs as JavaScript file extension (#118188)
Node uses `.cjs` as an extension for 'common javascript' modules.
2024-12-03 09:03:51 -08:00
mandymi
c9fbabfdc9
[ASTMatcher] Fix redundant macro expansion checks in getExpansionLocOfMacro (#117143)
A performance issue was descibed in #114521 

**Root Cause**: The function getExpansionLocOfMacro is responsible for
finding the expansion location of macros. When dealing with macro
parameters, it recursively calls itself to check the expansion of macro
arguments. This recursive logic redundantly checks previous macro
expansions, leading to significant performance degradation when macros
are heavily nested.
Solution
**Modification**: Track already processed macros during recursion.
Implementation Details:
Introduced a data structure to record processed macros.
Before each recursive call, check if the macro has already been
processed to avoid redundant calculations.
**Testing**: 
1. refer to #114521 
Finder->addMatcher(expr(isExpandedFromMacro("NULL")).bind("E"), this);
run clang-tidy on freecad/src/Mod/Path/App/AreaPyImp.cpp 
clang-tidy src/Mod/Path/App/AreaPyImp.cpp -checks=-*,testchecker
-p=build/compile_commands.json
checker runs normally
2. check-clang-unit pass
2024-12-03 11:22:56 -05:00
Vladislav Belov
e1cb316cfd
Reapply "[clang] Fix name lookup for dependent bases" (#118003)
Unlike the previous version
(https://github.com/llvm/llvm-project/pull/114978), this patch also
removes an unnecessary assert that causes Clang to crash when compiling
such tests. (clang/lib/AST/DeclCXX.cpp)

https://lab.llvm.org/buildbot/#/builders/52/builds/4021

```c++
template <class T> 
class X {
public:
  X() = default;
  virtual ~X() = default;

  virtual int foo(int x, int y, T &entry) = 0;

  void bar() {
    struct Y : public X<T> {
      Y() : X() {}

      int foo(int, int, T &) override {
        return 42;
      }
    };
  }
};
```

the assertions: 

```c++
llvm-project/clang/lib/AST/DeclCXX.cpp:2508: void clang::CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *): Assertion `!MD->getParent()->isDependentContext() && "Can't add an overridden method to a class template!"' failed.
```

I believe that this assert is unnecessary and contradicts the logic of
this patch. After its removal, Clang was successfully built using
itself, and all tests passed.
2024-12-03 16:46:01 +03:00
Haojian Wu
356df2dd72 Revert "[clang] Warn [[clang::lifetimebound]] misusages on types (#118281)"
Temporarily revert the patch to give downstream teams some time to clean up their codebases.

This reverts commit 4849d593ab07c47f9f520bea636f62d159d57006.
2024-12-03 12:13:13 +01:00
Maksim Ivanov
4849d593ab
[clang] Warn [[clang::lifetimebound]] misusages on types (#118281)
Emit the "cannot be applied to types" warning instead of silently
ignoring the attribute when it's attempted to be used on a type (instead
of a function argument or the function definition).

Before this commit, the warning has been printed when the attribute was
(mis)used on a decl-specifier, but not in other places in a declarator.

Examples where the warning starts being emitted with this commit:

```
  int * [[clang::lifetimebound]] x;

  void f(int * [[clang::lifetimebound]] x);

  void g(int * [[clang::lifetimebound]]);
```

Note that the last example is the case of an unnamed function parameter.
While in theory Clang could've supported the `[[clang::lifetimebound]]`
analysis for unnamed parameters, it doesn't currently, so the commit at
least makes the situation better by highlighting this as a warning
instead of a silent ignore - which was reported at #96034.
2024-12-03 11:10:11 +01:00
Younan Zhang
9ea993f975
[Clang] Recover GLTemplateParameterList for generic lambdas in RebuildLambdaScopeInfo (#118176)
The NTTP argument appearing inside a trailing return type of a generic
lambda would have us check for potential lambda captures, where the
function needs GLTemplateParameterList of the current LSI to tell
whether the lambda is generic.

The lambda scope in this context is rebuilt by the
LambdaScopeForCallOperatorInstantiationRAII when substituting the lambda
operator during template argument deduction. Thus, I think the template
parameter list should be preserved in the rebuilding process, as it
seems otherwise innocuous to me.

Fixes #115931
2024-12-03 10:10:17 +08:00
c8ef
814ed93e48
[clang] constexpr built-in elementwise bitreverse function. (#118177)
Part of #51787.

This patch adds constexpr support for the built-in elementwise
bitreverse function.
2024-12-03 09:33:53 +08:00
Oleksandr T.
071da9261b
[Clang] ensure mangled names are valid identifiers before being suggested in ifunc/alias attributes notes (#118170)
Fixes #112205

--- 

Commit that introduced this feature -
9306ef9750
2024-12-02 18:16:47 +02:00
Oleksandr T.
4ad4d34a22
Revert [Clang] prevent errors for deduction guides using deduced type aliases (#118165)
Reverts https://github.com/llvm/llvm-project/pull/117450

---

Revert https://github.com/llvm/llvm-project/pull/117450 because the
prior behavior aligns with the standard - _`template-name`_ in the
_`simple-template-id`_ in the return type shall be the actual name of a
class template rather than some equivalent alias template. Details
https://github.com/llvm/llvm-project/issues/54909#issuecomment-2508418355.
2024-12-02 17:19:19 +02:00
antangelo
54fcf3ec26
[clang] Implement P3176R1: The Oxford variadic comma (#117524)
Emit a deprecation warning when a variadic parameter in a
parameter-declaration-clause is not preceded by a comma for C++26.
2024-12-02 03:53:55 -05:00
Congcong Cai
010317e173
[clang-tidy][use-internal-linkage]fix false positives for ExportDecl (#117901)
Fixed: #97190
2024-12-02 13:59:55 +08:00
vabridgers
8ac2b77a11
[analyzer] Remove alpha.core.IdenticalExpr Checker (#114715)
This change removes the alpha.core.IdenticalExpr static analysis checker
since it's checks are present in the clang-tidy checks
misc-redundant-expression and bugprone-branch-clone. This check was
implemented as a static analysis check using AST matching, and since
alpha and duplicated in 2 clang-tidy checks may be removed.

Co-authored-by: Vince Bridgers <vince.a.bridgers@ericsson.com>
2024-11-29 17:38:59 -06:00
Oleksandr T.
be75a14207
[Clang] fix crash due to incorrect argument position in merging deduced template arguments (#118041)
Fixes #113659
2024-11-29 21:26:59 +02:00
Haojian Wu
26baa00908
[clang] Diagnose dangling references for parenthesized aggregate initialization. (#117690)
Unlike brace initialization, the parenthesized aggregate initialization
in C++20 does not extend the lifetime of a temporary object bound to a
reference in an aggreate. This can lead to dangling references:

```
struct A { const int& r; };
 A a1(1); // well-formed, but results in a dangling reference.
 ``` 

With this patch, clang will diagnose this common dangling issues.

Fixes #101957
2024-11-29 10:15:19 +01:00
vabridgers
e034c4ef7b
[analyzer] Modernize, improve and promote chroot checker (#117791)
This change modernizes, improves and promotes the chroot checker from
alpha to the Unix family of checkers. This checker covers the POS05
recommendations for use of chroot.

The improvements included modeling of a success or failure from chroot
and not falsely reporting a warning along an error path. This was made
possible through modernizing the checker to be flow sensitive.

---------

Co-authored-by: einvbri <vince.a.bridgers@ericsson.com>
Co-authored-by: Balazs Benics <benicsbalazs@gmail.com>
2024-11-29 08:23:08 +01:00
AlexErofeev
18760ce0fd
[Clang][AST] Fix PackIndexingExpr AST printout (#117947)
Fixes #116486 
Also added a test
2024-11-29 14:04:25 +08:00