1904 Commits

Author SHA1 Message Date
Aaron Ballman
d99cfa0539 [C99] Claim conformance to WG14 N631 and WG14 N696
Both of these relate to handling of standard pragmas. N631 is about
various STDC pragmas being included in the standard at all, and N696
is about whether macros are expanded in standard pragmas (they're not).
2024-03-25 12:55:43 -04:00
Aaron Ballman
7ee1007edd [C99] Claim full support for WG14 N772
No tests are added because existing tests cover this. The thrust of the
paper is that an implementation needs to support including a header
file whose name is eight character or less and contains only letters
and numbers; we definitely manage this.
2024-03-25 12:19:40 -04:00
Aaron Ballman
6fd3677fb4 Fixing a think-o with swapped information 2024-03-25 12:01:48 -04:00
Discookie
37785fedab
[clang][analyzer] Bring cplusplus.ArrayDelete out of alpha (#83985)
The checker finds a type of undefined behavior, where if the type of a
pointer to an object-array is different from the objects' underlying
type, calling `delete[]` is undefined, as the size of the two objects
might be different.

The checker has been in alpha for a while now, it is a simple checker
that causes no crashes, and considering the severity of the issue, it
has a low result-count on open-source projects (in my last test-run on
my usual projects, it had 0 results).

This commit cleans up the documentation and adds docs for the limitation
related to tracking through references, in addition to moving it to
`cplusplus`.

---------

Co-authored-by: Balazs Benics <benicsbalazs@gmail.com>
Co-authored-by: whisperity <whisperity@gmail.com>
2024-03-25 10:08:56 +00:00
Corentin Jabot
b723c57f8f [Clang] Update the C++ page with papers approved in Tokyo 2024-03-23 10:04:45 +09:00
Aaron Ballman
527a624205 [C11] Update the status of N1365 on constant expression handling
This paper is about constant expression handling in the presence of
FLT_EVAL_METHOD, which we handle via insertion of implicit cast nodes
in the AST.
2024-03-22 12:50:18 -04:00
Aaron Ballman
d2f684685a [C99] Update status of DR290, which we do not yet implement 2024-03-22 12:50:18 -04:00
Aaron Ballman
d231e3b10e [C11] Add test & update status of N1282 and DR087
Our existing diagnostics for catching unsequenced modifications handles
test coverage for N1282, which is correcting the standard based on the
resolution of DR087.
2024-03-22 10:17:50 -04:00
Aaron Ballman
7955bde64e [C11] Add test coverage for N1310 and claim conformance
This is about the best I could do for testing that `signed char` does
not have any padding bits.
2024-03-20 15:08:43 -04:00
Fangrui Song
9936ac3083
[docs] Prefer --gcc-install-dir= to deprecated GCC_INSTALL_PREFIX (#85458)
Setting GCC_INSTALL_PREFIX leads to a warning (#77537).

Link:
https://discourse.llvm.org/t/add-gcc-install-dir-deprecate-gcc-toolchain-and-remove-gcc-install-prefix/65091
Link:
https://discourse.llvm.org/t/correct-cmake-parameters-for-building-clang-and-lld-for-riscv/72833
2024-03-18 13:11:44 -07:00
Amy Huang
f9a1478200
Reapply "[Clang][C++23] Implement P2448R2 ..." (#85136) (#85145)
This reverts commit 003e292f9895a9cf4e30688269efa668d1fcbb09 because
there were dependent changes in the codebase that now fail.
2024-03-13 23:15:01 +00:00
Amy Huang
003e292f98
Revert "[Clang][C++23] Implement P2448R2 ..." (#85136)
Revert "[Clang][C++23] Implement P2448R2: Relaxing some constexpr
restrictions (#77753)"

This reverts commit 99500e8c08a4d941acb8a7eb00523296fb2acf7a because it
causes a behavior change for std=c++20. See
https://github.com/llvm/llvm-project/pull/77753.
2024-03-13 21:53:38 +00:00
cor3ntin
ceaf4a0aab
[Clang] Fix status of P1774 Portable assumptions 2024-03-09 12:22:40 +01:00
Sirraide
2b5f68a5f6
[Clang][C++23] Implement P1774R8: Portable assumptions (#81014)
This implements the C++23 `[[assume]]` attribute.

Assumption information is lowered to a call to `@llvm.assume`, unless the expression has side-effects, in which case it is discarded and a warning is issued to tell the user that the assumption doesn’t do anything. A failed assumption at compile time is an error (unless we are in `MSVCCompat` mode, in which case we don’t check assumptions at compile time).

Due to performance regressions in LLVM, assumptions can be disabled with the `-fno-assumptions` flag. With it, assumptions will still be parsed and checked, but no calls to `@llvm.assume` will be emitted and assumptions will not be checked at compile time.
2024-03-09 12:07:16 +01:00
Haojian Wu
7415524b45
[clang] Implement CTAD for type alias template. (#77890)
Fixes #54051

This patch implements the C++20 feature -- CTAD for alias templates (P1814R0, specified in https://eel.is/c++draft/over.match.class.deduct#3). It is an initial patch:
- it cover major pieces, thus it works for most cases;
- the big missing piece is to implement the associated constraints (over.match.class.deduct#3.3) for the synthesized deduction guides, see the FIXME in code and tests;
- Some enhancements on the TreeTransform&TemplateInstantiator to allow performing instantiation on `BuildingDeductionGuides` mode;
2024-03-08 14:24:03 +01:00
Vlad Serebrennikov
b6a340023d
[clang] Respect field alignment in layout compatibility of structs (#84313)
This patch implements
[CWG2586](https://cplusplus.github.io/CWG/issues/2583.html) "Common
initial sequence should consider over-alignment". Note that alignment of
union members doesn't have to match, as layout compatibility of unions
is not defined in terms of common initial sequence
(http://eel.is/c++draft/class.mem.general#25).
2024-03-08 11:31:00 +04:00
Vlad Serebrennikov
41572177d1
[clang] Add CodeGen tests for CWG 5xx issues (#84303)
This patch covers
[CWG519](https://cplusplus.github.io/CWG/issues/519.html) "Null pointer
preservation in `void*` conversions",
[CWG571](https://cplusplus.github.io/CWG/issues/571.html) "References
declared const".
2024-03-07 22:38:44 +04:00
cor3ntin
48dd118f56
[Clang] Fix approved revision of P2266 2024-03-07 14:40:30 +01:00
Mariya Podchishchaeva
99500e8c08
[Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (#77753)
Per
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2448r2.html
function/constructor/destructor can be marked `constexpr` even though it
never produces a constant expression.
Non-literal types as return types and parameter types of functions
marked `constexpr` are also allowed.
Since this is not a DR, the diagnostic messages are still preserved for
C++ standards older than C++23.
2024-03-07 09:36:50 +01:00
Botond István Horváth
63afcbbeea
[clang][Sema] Bugfix for choosing the more specialized overload (#83279)
There was a bug in Clang where it couldn't choose which overload
candidate was more specialized if it was comparing a member-function to
a non-member function. Previously, this was detected as an ambiguity,
now Clang chooses correctly.

This patch fixes the bug by fully implementing CWG2445 and moving the
template transformation described in `[temp.func.order]` paragraph 3
from `isAtLeastAsSpecializedAs()` to
`Sema::getMoreSpecializedTemplate()` so we have the transformed
parameter list during the whole comparison. Also, to be able to add the
correct type for the implicit object parameter
`Sema::getMoreSpecializedTemplate()` has new parameters for the object
type.

Fixes #74494, fixes #82509
2024-03-06 15:03:21 +01:00
Aaron Ballman
ae79854e4d Update C status page now that Clang 18.x is released 2024-03-06 08:58:04 -05:00
Corentin Jabot
33e312137b [Clang] Mark papers & core issues implemented in clang 18 as released 2024-03-06 14:47:53 +01:00
Mariya Podchishchaeva
aced81c0a5
[C23] Implement N3018: The constexpr specifier for object definitions (#73099)
The implementation mostly reuses C++ code paths where possible,
including narrowing check in order to provide diagnostic messages in
case initializer for constexpr variable is not exactly representable in
target type.

The following won't work due to lack of support for other features:
- Diagnosing of underspecified declarations involving constexpr
- Constexpr attached to compound literals

Also due to lack of support for char8_t some of examples with utf-8
strings don't work properly.

Fixes https://github.com/llvm/llvm-project/issues/64742
2024-03-06 09:46:35 +01:00
Vlad Serebrennikov
7a0acccd81
[clang] Add some CodeGen tests for CWG 4xx issues (#83715)
This patch covers the following defect reports:
[CWG438](https://cplusplus.github.io/CWG/issues/438.html) "Possible flaw
in wording for multiple accesses to object between sequence points",
[CWG439](https://cplusplus.github.io/CWG/issues/439.html) "Guarantees on
casting pointer back to cv-qualified version of original type",
[CWG441](https://cplusplus.github.io/CWG/issues/441.html) "Ordering of
static reference initialization",
[CWG462](https://cplusplus.github.io/CWG/issues/462.html) "Lifetime of
temporaries bound to comma expressions",
[CWG492](https://cplusplus.github.io/CWG/issues/492.html) "`typeid`
constness inconsistent with example".

[CWG475](https://cplusplus.github.io/CWG/issues/475.html) "When is
`std::uncaught_exception()` true? (take 2)" requires a libc++abi test.
As for [CWG454](https://cplusplus.github.io/CWG/issues/454.html) "When
is a definition of a static data member required?", I don't feel
confident in my understanding of it, so skipping over it.
2024-03-06 12:21:52 +04:00
Vlad Serebrennikov
5c24c31649
[clang] Implement CWG2759 "[[no_unique_address] and common initial sequence" (#82607)
This patch implements said defect report resolution by adding additional
check to common initial sequence evaluation. Consequently, this fixes
CWG2759.
2024-02-22 22:30:31 +04:00
Vlad Serebrennikov
73185854a3
[clang] Implement CWG1719 "Layout compatibility and cv-qualification revisited" (#82358)
This patch updates our internal notion of `layout-compatible` to ignore cv-qualification,
which in turn fixes `__is_layout_compatible` intrinsic.
2024-02-21 19:02:20 +04:00
Vlad Serebrennikov
df81055955
[clang] Do less advertising for unresolved issues in cxx_dr_status.html (#78836)
This patch places additional requirement on tests for open issues to
specify what do they test, and reduce their advertising on
`cxx_dr_status.html`.

Tests for open issues have to either provide date of the proposed
resolution they test, or a paper number that attempts to resolve the
issue. Examples from this patch: `// dr1223: 17 drafting 2023-05-12`,
`// dr2049: 18 drafting P2308R1`, `// dr2335: no drafting 2018-06`.

Tests for open issues are no longer advertised in `cxx_dr_status.html`
as tests for resolved issues. Instead, they are specified as `Not
Resolved*` (note the asterisk). Such statuses have a tooltip with the
following kind of text:
`Clang 17 implements 2023-05-12 resolution`
`Clang does not implement 2018-06-04 resolution` 
`Clang 18 implements P2308R1 resolution`
I admit that the wording is a bit crude, but I tried to minimize amount
of boilerplate in the `make_cxx_dr_status`. Hopefully, this whole setup
matches [C++ compiler
support](https://en.cppreference.com/w/cpp/compiler_support) page on
cppreference enough for people to catch up.

This patch also implement a quality-of-life feature for users of
`make_cxx_dr_status`: now script is able to report multiple bad `// dr`
comments in a single run.

This has also been discussed in a PR for CWG472 test:
https://github.com/llvm/llvm-project/pull/67948
2024-02-15 23:45:56 +04:00
Vlad Serebrennikov
346e7c7f68
[clang] Add some CodeGen tests for CWG 2xx issues (#80823)
This patch covers CWG issues
[201](https://cplusplus.github.io/CWG/issues/201.html),
[210](https://cplusplus.github.io/CWG/issues/210.html),
[292](https://cplusplus.github.io/CWG/issues/292.html).

[CWG208](https://cplusplus.github.io/CWG/issues/208.html) is not
covered, as it actually requires a libcxxabi test.

Resolution of CWG292 has been superseded by
[P0145R3](https://wg21.link/p0145r3) "Refining Expression Evaluation
Order for Idiomatic C++"
(see changes to paragraph 5.3.4/18).
2024-02-13 12:17:46 +04:00
Vlad Serebrennikov
a9845d6022
[clang] Add some CodeGen tests for CWG 1xx issues (#80338)
Covers CWG issues
[124](https://cplusplus.github.io/CWG/issues/124.html)
[185](https://cplusplus.github.io/CWG/issues/185.html),
[193](https://cplusplus.github.io/CWG/issues/193.html),
[199](https://cplusplus.github.io/CWG/issues/199.html).

I also looked at [190](https://cplusplus.github.io/CWG/issues/190.html),
but concluded that we should try to test it via C++20
`std::is_layout_compatible` first.

I tried to group tests under `dr1xx-codegen.cpp`, but found out that
CodeGen can arbitrarily reorder function definitions in LLVM module. In
particular, interleaving between regular function definitions and
destructor definitions present in the source might not be preserved,
which messes up FileCheck directives. `CHECK-DAG` can help with that,
but its interaction with `CHECK-LABEL` (lack of thereof) would require
me to relax tests too much.
2024-02-12 22:36:06 +04:00
Balázs Kéri
2b5e4eeb26
[clang][analyzer] Remove 'alpha.core.CallAndMessageUnInitRefArg' from documentation (NFC). (#81138)
This checker does not exist (any more?) but appeared in the
documentation. No other references to CallAndMessageUnInitRefArg are
found in the full clang code.
2024-02-12 15:30:58 +01:00
Vlad Serebrennikov
50c5107f42
[clang] Add tests for DRs about inheriting constructors (#79981)
Covers CWG issues
[1150](https://cplusplus.github.io/CWG/issues/1150.html),
[1487](https://cplusplus.github.io/CWG/issues/1487.html),
[1567](https://cplusplus.github.io/CWG/issues/1567.html),
[1738](https://cplusplus.github.io/CWG/issues/1738.html),
[2273](https://cplusplus.github.io/CWG/issues/2273.html),
[2277](https://cplusplus.github.io/CWG/issues/2277.html),
[2356](https://cplusplus.github.io/CWG/issues/2356.html),
[2504](https://cplusplus.github.io/CWG/issues/2504.html).

On top of the wording in proposed resolutions,
[P0136R1](https://wg21.link/p0136r1) "Rewording inheriting constructors
(core issue 1941 et al)" is a very relevant paper.

Note that status for 1738 `sup P0136R1` is not officially recognized by
CWG, but saying `yes` or `no` seems even more confusing to me. Official
resolution is to reject certain code, but Clang is the only
implementation that still rejects it to this day:
https://godbolt.org/z/b1W8jc1o5. GCC rejected it until 9, now it's
accepted: https://godbolt.org/z/of6oh4sdT
2024-02-09 19:20:10 +04:00
yronglin
0aff71c178
[Clang] Implement P2718R0 "Lifetime extension in range-based for loops" (#76361)
Implement P2718R0 "Lifetime extension in range-based for loops"
(https://wg21.link/P2718R0)

Differential Revision: https://reviews.llvm.org/D153701

---------

Signed-off-by: yronglin <yronglin777@gmail.com>
2024-01-30 06:48:14 +08:00
cor3ntin
ad1a65fcac
[Clang][C++26] Implement Pack Indexing (P2662R3). (#72644)
Implements https://isocpp.org/files/papers/P2662R3.pdf

The feature is exposed as an extension in older language modes.
Mangling is not yet supported and that is something we will have to do before release.
2024-01-27 10:23:38 +01:00
Vlad Serebrennikov
43e46c546a
[clang] Add test for CWG472 (#67948)
https://cplusplus.github.io/CWG/issues/472.html
It has drafting status, but I think CWG has reached consesus on the
behavior.
Related: #16602
2024-01-25 19:00:17 +04:00
Alexander Kornienko
6e4930c675 Revert "[SemaCXX] Implement CWG2137 (list-initialization from objects of the same type) (#77768)"
This reverts commit 924701311aa79180e86ad8ce43d253f27d25ec7d. Causes compilation
errors on valid code, see
https://github.com/llvm/llvm-project/pull/77768#issuecomment-1908062472.
2024-01-24 21:42:38 +01:00
Andrey Ali Khan Bolshakov
5518a9d767
[c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (#78041)
Previously committed as 9e08e51a20d0d2b1c5724bb17e969d036fced4cd, and
reverted because a dependency commit was reverted, then committed again
as 4b574008aef5a7235c1f894ab065fe300d26e786 and reverted again because
"dependency commit" 5a391d38ac6c561ba908334d427f26124ed9132e was
reverted. But it doesn't seem that 5a391d38ac6c was a real dependency
for this.

This commit incorporates 4b574008aef5a7235c1f894ab065fe300d26e786 and
18e093faf726d15f210ab4917142beec51848258 by Richard Smith (@zygoloid),
with some minor fixes, most notably:

- `UncommonValue` renamed to `StructuralValue`

- `VK_PRValue` instead of `VK_RValue` as default kind in lvalue and
member pointer handling branch in
`BuildExpressionFromNonTypeTemplateArgumentValue`;

- handling of `StructuralValue` in `IsTypeDeclaredInsideVisitor`;

- filling in `SugaredConverted` along with `CanonicalConverted`
parameter in `Sema::CheckTemplateArgument`;

- minor cleanup in
`TemplateInstantiator::transformNonTypeTemplateParmRef`;

- `TemplateArgument` constructors refactored;

- `ODRHash` calculation for `UncommonValue`;

- USR generation for `UncommonValue`;

- more correct MS compatibility mangling algorithm (tested on MSVC ver.
19.35; toolset ver. 143);

- IR emitting fixed on using a subobject as a template argument when the
corresponding template parameter is used in an lvalue context;

- `noundef` attribute and opaque pointers in `template-arguments` test;

- analysis for C++17 mode is turned off for templates in
`warn-bool-conversion` test; in C++17 and C++20 mode, array reference
used as a template argument of pointer type produces template argument
of UncommonValue type, and
`BuildExpressionFromNonTypeTemplateArgumentValue` makes
`OpaqueValueExpr` for it, and `DiagnoseAlwaysNonNullPointer` cannot see
through it; despite of "These cases should not warn" comment, I'm not
sure about correct behavior; I'd expect a suggestion to replace `if` by
`if constexpr`;

- `temp.arg.nontype/p1.cpp` and `dr18xx.cpp` tests fixed.
2024-01-21 21:28:57 +01:00
Aaron Ballman
997ffce43c [C23] Implement N2490, Remove trigraphs??!
This follows the same implementation logic as with C++ and is
compatible with the GCC behavior in C.

Trigraphs are enabled by default in -std=c* conformance modes before
C23, but are disabled in GNU and Microsoft modes as well as in C23 or
later.
2024-01-21 13:20:56 -05:00
Vlad Serebrennikov
9eb0f86c27
[clang] Implement CWG1878 "operator auto template" (#78103)
C++14 introduced deduced return type for regular functions, but shortly after [CWG1878](https://wg21.link/cwg1878) was filed and resolved to disallow deduced return types in conversion function templates. So this patch diagnoses such usage of deduced return type in C++14 mode onwards.

Fixes #51776
2024-01-20 12:23:08 +04:00
Mital Ashok
924701311a
[SemaCXX] Implement CWG2137 (list-initialization from objects of the same type) (#77768)
Closes #77638, #24186

Rebased from <https://reviews.llvm.org/D156032>, see there for more
information.

Implements wording change in [CWG2137](https://wg21.link/CWG2137) in the
first commit.

This also implements an approach to [CWG2311](https://wg21.link/CWG2311)
in the second commit, because too much code that relies on `T{ T_prvalue}` 
being an elision would break. Because that issue is still open and
the CWG issue doesn't provide wording to fix the issue, there may be
different behaviours on other compilers.
2024-01-19 21:10:51 +01:00
Vlad Serebrennikov
f4fbbebb5e
[clang] Add test for CWG1807 (#77637)
The test checks that objects in arrays are destructed in reverse order during stack unwinding.

This patch is trying to establish a precedent how codegen tests for C++ defect report test suite should be written. Refer to PR for exact reasoning.
2024-01-18 17:14:25 +04:00
cor3ntin
4e64159c86
[Clang] Implement CWG2598: Union of non-literal types (#78195)
A union is considered a literal type unless it has no non-literal
member.

This resolves CWG2096 (which makes unions with literal members literal)
and CWG2598 (empty unions are literal types).

Fixes #77924
2024-01-17 06:16:12 +01:00
Vlad Serebrennikov
91b53a2c79
[clang] Add tests for DRs about complete-class context (#77444)
[P1787](https://wg21.link/p1787): The intent for CWG2335 (contra those of the older CWG1890, CWG1626, CWG1255, and CWG287) is supported by retaining the unrestricted forward lookup in complete-class contexts (despite current implementation behavior for non-templates).

Wording: The declaration set is the result of a single search in the scope of C for N from immediately after the class-specifier of C if P is in a complete-class context of C or from P otherwise. [Drafting note: The plan for CWG2335 is to describe forbidden dependency cycles among the complete-class contexts of a class. — end drafting note] ([class.member.lookup]/4)

Complete-class context is described in [class.mem.general] [p7](http://eel.is/c++draft/class#mem.general-7) and
[p8](http://eel.is/c++draft/class#mem.general-8). In this patch I add tests only for CWG issues that fall under current definition of complete-class context, because I'm not sure how CWG1255 and CWG287 are going to work. That's why I skip over them, but mark CWG1308 as superseded by CWG1330.
2024-01-14 02:27:01 +04:00
Vlad Serebrennikov
d8cd55414f
[clang] Add test for CWG1350 (#78040)
Test is based on [P0136R1](https://wg21.link/p0136r1) wording instead of proposed resolution in the issue itself.

This patch also expands related CWG1573 test with an additional test case. Existing `3.9` status of 1573 is still relevant even with this new test case.
2024-01-14 02:19:25 +04:00
Corentin Jabot
9d97247e26 [clang] Fix color consistency in C paper tracking web page 2024-01-11 10:23:37 +01:00
Corentin Jabot
33e5db6e04 [clang] Improve colors in status tracking web pages.
Use a consistent, more pastel color for unknown status
in papers and issues tracking pages
2024-01-11 10:21:51 +01:00
Vlad Serebrennikov
d0918a20d2
[clang] Add tests for CWG1800-1804 (#77509)
Covers C++ core issues 1800, 1801, 1802, 1803, 1804.
2024-01-10 12:51:04 +04:00
Vlad Serebrennikov
c7d404ea72
[clang] Update cxx_dr_status.html (#77372)
This patch updates `cxx_dr_status.html` to bring it in sync with Core Issues List Revision 113.
2024-01-09 14:52:05 +04:00
Artem Dergachev
ef3f476097 [attributes][analyzer] Implement [[clang::suppress]] - suppress static analysis warnings.
The new attribute can be placed on statements in order to suppress
arbitrary warnings produced by static analysis tools at those statements.

Previously such suppressions were implemented as either informal comments
(eg. clang-tidy `// NOLINT:`) or with preprocessor macros (eg.
clang static analyzer's `#ifdef __clang_analyzer__`). The attribute
provides a universal, formal, flexible and neat-looking suppression mechanism.

Implement support for the new attribute in the clang static analyzer;
clang-tidy coming soon.

The attribute allows specifying which specific warnings to suppress,
in the form of free-form strings that are intended to be specific to
the tools, but currently none are actually supported; so this is also
going to be a future improvement.

Differential Revision: https://reviews.llvm.org/D93110
2023-12-13 18:09:16 -08:00
DonatNagyE
c873f77e87
[analyzer] Move alpha checker EnumCastOutOfRange to optin (#67157)
The checker EnumCastOutOfRange verifies the (helpful, but not
standard-mandated) design rule that integer to enum casts should not
produce values that don't have a corresponding enumerator. As it was
improved and cleaned up by recent changes, this commit renames it from
`alpha.cplusplus.EnumCastOutOfRange` to `optin.core.EnumCastOutOfRange`
to reflect that it's no longer alpha quality.

As this checker handles a basic language feature (which is also present
in plain C), I moved it to a "core" subpackage within "optin".

In addition to the renaming, this commit cleans up the documentation in
`checkers.rst` and adds the new example code to a test file to ensure
that it's indeed producing the behavior claimend in the documentation.
2023-12-12 16:29:37 +01:00
Vlad Serebrennikov
57eb2054e3 [clang][NFC] Fill in historical data on when C++ DRs 2000-2799 were fixed 2023-12-09 11:12:54 +03:00