22399 Commits

Author SHA1 Message Date
Kazu Hirata
f002f300c5
[clang] Remove unused local variables (NFC) (#138453) 2025-05-04 10:51:40 -07:00
Younan Zhang
1b60b83ada
[Clang] Don't retain template FoundDecl for conversion function calls (#138377) 2025-05-04 19:27:08 +08:00
cor3ntin
1101b76732
[Clang] Implement CWG3005 Function parameters should never be name-independent (#138245)
We already attempted to implement this (it was the intent of the paper),
in that parameters were never considered name-independent. However, we
failed to check that any previously found parameter declaration was also
name-independent.

Note that, as worded, the current resolution is insufficient (I wrote to
CWG with better wording), but there is some consensus on the design
outcome.

Fixes #136373
2025-05-02 20:56:28 +02:00
cor3ntin
cce6de8313
[Clang] Never consider conversion from single-element braced-init-list perfect (#138307)
We might prefer a template std::initializer list constructor.

Fix a regression introduced by #136203
https://github.com/llvm/llvm-project/pull/136203#issuecomment-2843498895

GCC had a similar issue and a similar fix
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100963
2025-05-02 20:56:02 +02:00
Krzysztof Parzyszek
52c62364e7
[OpenMP] Remove "alternativeName" from Clause and Directive classes (#138179)
The "alternativeName" was introduced ~5 years ago in D82405, and at the
moment it has only one use, the one that the original change introduced.

OpenMP 6.0 spec has introduced different spellings of some directives,
but the "alternativeName" is not an adequate mechanism to implement it.

For those reasons remove the "alternativeName" member from both Clause
and Directive in DirectiveBase.td.

Since the alternativeName text appeared in a number of clang OpenMP
tests, implement `getOpenMPClauseNameForDiag` in SemaOpenMP.cpp to
preserve the text of the diagnostics.
2025-05-02 13:02:24 -05:00
cor3ntin
e59ed0fb0f
[Clang] __has_unique_object_representations should not accept Incomplete[] (#138291)
This implements [LWG4113](https://cplusplus.github.io/LWG/issue411)

This is technically a breaking change, but it's a fix, and I think
anyone who relies on this today is in a world of hurt.

Fixes #118350
2025-05-02 19:36:53 +02:00
erichkeane
b752822c44 [NFCI]Prospective fix for MVSC Build bot-
The previous code hits an assert inside the MSVC compiler version 16.8,
    which is our minimum supported version.  This patch looks on godbolt
    like it avoids this crash, so submitting it to hopefully unbreak the
    bot.
2025-05-02 09:42:16 -07:00
erichkeane
8313d2a8db [OpenACC] Fixup previous-clause diagnostics
Brought up in a previous review as a TODO, we could be better about how
we highlight what hte previous clause was, and how to show that the
'device_type' is the one being targetted.  This patch rewords the
diagnostics and updates a massive number of tests.
2025-05-02 09:35:32 -07:00
Aaron Ballman
a635bbf141
[C] Update the -Wdefault-const-init-unsafe wording (#138266)
This drops the "and is incompatible with C++" phrasing from the
diagnostic unless -Wc++-compat is explicitly passed. This makes the
diagnostic less confusing when it is on by default rather than enabled
because of C++ compatibility concerns
2025-05-02 12:23:40 -04:00
Erich Keane
e777e7a5d2
[OpenACC] Implement better dupe catching for device_type clauses (#138196)
Previously we just checked duplicates for a handful of clauses between
active device_type clauses. However, after looking into the
implementation for 'collapse', I discovered that duplicate device_type
identifiers with duplicate versions of htese clause are problematic.

This patch corrects this and now catches these conflicts.
2025-05-02 09:01:31 -07:00
Shafik Yaghmour
65438787c7
[Clang][NFC] assert IFaceT in SemaObjC::HandleExprPropertyRefExpr (#138026)
Static analysis flagged that we use IFaceT in HandleExprPropertyRefExpr
without checking even though getInterfaceType() can return nullptr. The
comments make it clear the assumption is that we will always have an
interface, so we will document this via an assert.

Fixes: https://github.com/llvm/llvm-project/issues/134954
2025-05-02 07:27:50 -07:00
Aaron Ballman
a4ceac7e3e
[C23] Implement WG14 N3037 (#132939)
This changes the type compatibility rules so that it is permitted to
redefine tag types within the same TU so long as they are equivalent
definitions.

It is intentionally not being exposed as an extension in older C
language modes. GCC does not do so and the feature doesn't seem
compelling enough to warrant it.
2025-05-02 09:19:21 -04:00
Aaron Ballman
543f112e14
[C] Add -Wjump-bypasses-init (#138009)
We already diagnose when a jump bypasses initialization in C++ because
such code is ill-formed there. However, we were not using this to
diagnose those same jumps in C.

-Wjump-bypasses-init is grouped under -Wc++-compat and diagnoses this
situation as a compatibility issue with C++. This diagnostic is off by
default.

The diagnostic could perhaps be enabled by default for C, but due to the
design of jump diagnostic handling, it not a trivial task. For now,
we'll add the diagnostic as off-by-default so we get incremental
improvement, but a follow-up could try to refactor jump diagnostics so
we can enable this by default in C and have it as a C++ compatibility
diagnostic as well.
2025-05-02 09:06:31 -04:00
Aaron Ballman
85c810060e
[C] Diagnose use of C++ keywords in C (#137234)
This adds a new diagnostic group, -Wc++-keyword, which is off by default
and grouped under -Wc++-compat. The diagnostic catches use of C++
keywords in C code.

This change additionally fixes an issue with -Wreserved-identifier not
diagnosing use of reserved identifiers in function parameter lists in a
function declaration which is not a definition.

Fixes https://github.com/llvm/llvm-project/issues/21898
2025-05-02 07:20:02 -04:00
Aaron Ballman
3d4f979e27
[C] Allow __attribute__((nonstring)) on multidimensional arrays (#138133)
This addresses post-commit review feedback from the Linux kernel folks
and improves compatibility with the same feature in GCC
2025-05-02 07:19:36 -04:00
Vlad Serebrennikov
cf2f13a867 [clang][NFC] Convert Sema::CCEKind to scoped enum 2025-05-02 14:01:40 +03:00
Vlad Serebrennikov
6e63b68389 [clang][NFC] Convert Sema::OverloadKind to scoped enum 2025-05-02 13:44:32 +03:00
Vlad Serebrennikov
4ba27780d3 [clang][NFC] Convert Sema::CorrectTypoKind to scoped enum 2025-05-02 13:20:41 +03:00
Vlad Serebrennikov
c0917ab2e1 [clang][NFC] Convert Sema::IfExistsResult to scoped enum 2025-05-02 13:05:37 +03:00
Vlad Serebrennikov
461255e0c1 [clang][NFC] Convert Sema::AllocationFunctionScope to scoped enum 2025-05-02 12:38:52 +03:00
Vlad Serebrennikov
ff8060a642 [clang][NFC] Convert Sema::AssignConvertType to scoped enum 2025-05-02 12:30:08 +03:00
Vlad Serebrennikov
d0dcfd4c68 [clang][NFC] Convert Sema::VarArgKind to scoped enum 2025-05-02 11:24:08 +03:00
Vlad Serebrennikov
db247ddc9d [clang][NFC] Convert Sema::ArithConvKind to scoped enum 2025-05-02 11:02:01 +03:00
Vlad Serebrennikov
140c2b6d08 [clang][NFC] Convert Sema::AllowFoldKind to scoped enum 2025-05-02 10:48:08 +03:00
Vlad Serebrennikov
0294c3615c [clang][NFC] Reland "Convert Sema::TryCaptureKind to scoped enum" 2025-05-02 09:39:16 +03:00
Vlad Serebrennikov
048befe9ef Revert "[clang][NFC] Convert Sema::TryCaptureKind to scoped enum"
This reverts commit be6497ff7583248d76a6710dd48cfeb63dd68f27.
2025-05-02 09:29:35 +03:00
Vlad Serebrennikov
be6497ff75 [clang][NFC] Convert Sema::TryCaptureKind to scoped enum 2025-05-02 09:25:58 +03:00
Vlad Serebrennikov
630a0ff2c2 [clang][NFC] Convert Sema::TrivialABIHandling to scoped enum 2025-05-02 09:12:52 +03:00
Vlad Serebrennikov
7e71db8463 [clang][NFC] Convert Sema::AvailabilityMergeKind to scoped enum 2025-05-02 07:56:57 +03:00
Vlad Serebrennikov
ed673aac7a [clang][NFC] Convert Sema::OffsetOfKind to scoped enum 2025-05-02 07:49:47 +03:00
Vlad Serebrennikov
8089c3d1ed [clang][NFC] Convert Sema::NonTagKind to scoped enum 2025-05-02 07:45:22 +03:00
Vlad Serebrennikov
09fb9adbd2 [clang][NFC] Convert Sema::NonTrivialCUnionContext to scoped enum 2025-05-02 07:39:54 +03:00
Vlad Serebrennikov
68fd69aca6 [clang][NFC] Convert Sema::PointerAuthDiscArgKind to scoped enum 2025-05-02 07:33:52 +03:00
Erich Keane
e5f09aac48
[OpenACC][CIR] Start work to lower 'loop' (#137972)
As can be seen by the comment, this ends up being a construct that is
going to be quite a lot of work in the future to make sure we properly
identify the upperbound, lowerbound, and step. For now, we just treat
the 'loop' as container so that we can put the 'for' loop into it.

In the future, we'll have to teach the OpenACC dialect how to derive the
upperbound, lowerbound, and step from the cir.for loop. Additionally,
we'll probably have to add a few more options to it so that we can give
it the recipes it needs to determine these for random access iterators.
For Integer and Pointer values, these should already be known.
2025-05-01 08:42:04 -07:00
cor3ntin
7ffaaf4752
[Clang] Warning as error for fold expressions over comparison operators (#136836)
We made chained comparisons an error.
Fold-expressions over a comparison operator produce chained comparisons,
so we should be consistent there too.

We only emit the warning when instantiating the fold expression so as
not to warn on types with user-defined comparisons.

Partially addresses #129570
2025-05-01 17:00:03 +02:00
Vlad Serebrennikov
001cc34275
[clang] Add scoped enum support to StreamingDiagnostic (#138089)
This patch adds templated `operator<<` for diagnostics that pass scoped
enums, saving people from `llvm::to_underlying()` clutter on the side of
emitting the diagnostic. This eliminates 80 out of 220 usages of
`llvm::to_underlying()` in Clang.

I also backported `std::is_scoped_enum_v` from C++23.
2025-05-01 17:03:47 +04:00
Aaron Ballman
bc9aa0f4c4
[C] Add -Wtentative-definition-compat (#137967)
This adds a new diagnostic to warn about redeclaration of a tentative
definition in C. This is incompatible with C++, so the new diagnostic
group is under -Wc++-compat.
2025-05-01 07:31:48 -04:00
Aaron Ballman
00f9ef282c
[C] Modify -Wdefault-const-init (#137961)
Post-commit review feedback on
https://github.com/llvm/llvm-project/pull/137166 raised a concern from
the Linux kernel about wanting to silence the new diagnostic when the
uninitialized object is a const member of a structure. These members can
be initialized later if the containing object is non-const, such as
through a call to memset, for example.

This splits the diagnostic groups into:
```
-Wc++-compat
  -Wdefault-const-init
    -Wdefault-const-init-field
    -Wdefault-const-init-var
    -Wdefault-const-init-unsafe
      -Wdefault-const-init-field-unsafe
      -Wdefault-const-init-var-unsafe
```

---------

Co-authored-by: Mariya Podchishchaeva <mariya.podchishchaeva@intel.com>
2025-05-01 07:08:06 -04:00
Vlad Serebrennikov
5f3e5df481 [clang][NFC] Convert Sema::BuiltinCountedByRefKind to scoped enum 2025-05-01 08:01:03 +03:00
Vlad Serebrennikov
c2c0ef50a1 [clang][NFC] Convert Sema::VariadicCallType to scoped enum 2025-05-01 07:01:06 +03:00
Justin Bogner
ae6b4b23ea
[HLSL] Overloads for lerp with a scalar weight (#137877)
This adds overloads for the `lerp` function that accept a scalar for the
weight parameter by splatting it into the appropriate vector.

Fixes #137827
2025-04-30 12:30:06 -07:00
erichkeane
ea0e6e3383 [OpenACC] Improve 'loop' content restrictions
The 'loop' construct has some limitations that are not particularly
clear on what can be in the for-loop. This patch adds some restriction
so that the increment can only be a addition or subtraction operation,
   BUT starts allowing Itr = Itr +/- N forms.
2025-04-30 12:02:52 -07:00
Helena Kotas
2a5ee2501d
[HLSL] Allow resource annotations to specify only register space (#135287)
Specifying only `space` in a `register` annotation means the compiler
should implicitly assign a register slot to the resource from the
provided virtual register space.

Closes #133346
2025-04-30 10:27:27 -07:00
Aaron Ballman
e8ae779471
[C] Add diagnostic + attr for unterminated strings (#137829)
This introduces three things related to intialization like:

char buf[3] = "foo";

where the array does not declare enough space for the null terminator
but otherwise can represent the array contents exactly.

1) An attribute named 'nonstring' which can be used to mark that a
   field or variable is not intended to hold string data.

2) -Wunterminated-string-initialization, which is grouped under
   -Wextra, and diagnoses the above construct unless the declaration
   uses the 'nonstring' attribute.

3) -Wc++-unterminated-string-initialization, which is grouped under
   -Wc++-compat, and diagnoses the above construct even if the
   declaration uses the 'nonstring' attribute.

Fixes #137705
2025-04-30 10:14:18 -04:00
halbi2
6dfd354571
[clang] ownership_returns attribute takes no more than 2 arguments (#137897) 2025-04-30 19:29:37 +08:00
Mariya Podchishchaeva
f62f36b91d
[clang][NFC] Avoid a duplicate variable in SemaExprCXX.cpp (#137464) 2025-04-30 10:30:08 +02:00
Helena Kotas
f1750300aa
[HLSL] Resource initialization by constructors (#135120)
- Adds resource constructor that takes explicit binding for all resource
classes.
- Updates implementation of default resource constructor to initialize
resource handle to `poison`.
- Removes initialization of resource classes from Codegen.
- Initialization of `cbuffer` still needs to happen in `CGHLSLRuntime`
because it does not have a corresponding resource class type.
- Adds `ImplicitCastExpr` for builtin function calls. Sema adds these
automatically when a method of a template class is instantiated, but
some resource classes like `ByteAddressBuffer` are not templates so they
need to have this added explicitly.

Design proposal: llvm/wg-hlsl#197

Closes #134154
2025-04-29 18:42:22 -07:00
Akira Hatanaka
6bb4ce0f6f
Silence spurious -Wnontrivial-memcall warnings in C mode (#137429)
clang currently issues a warning when memset is used on a struct that
contains an address-discriminated pointer field, even though this is
entirely valid behavior.

For example:

```
struct S {
  int * __ptrauth(1, 1, 100) p;
} s;

memset(&s, 0, sizeof(struct S));
```

Only allow the warning to be emitted in C++ mode to silence the warning.

rdar://142495870
2025-04-29 18:37:57 -07:00
Aaron Ballman
2f976956e5
[C] Diagnose declarations hidden in C++ (#137368)
This introduces a new diagnostic, -Wc++-hidden-decl, which is grouped
under -Wc++-compat, that diagnoses declarations which are valid in C but
invalid in C++ due to the type being at the wrong scope. e.g.,
```
  struct S {
    struct T {
      int x;
    } t;
  };

  struct T t; // Valid C, invalid C++
```
This is implementing the other half of #21898
2025-04-29 07:58:00 -04:00
Aaron Ballman
df267d77f6
[C] Add new -Wimplicit-int-enum-cast to -Wc++-compat (#137658)
This introduces a new diagnostic group to diagnose implicit casts from
int to an enumeration type. In C, this is valid, but it is not
compatible with C++.

Additionally, this moves the "implicit conversion from enum type to
different enum type" diagnostic from `-Wenum-conversion` to a new group
`-Wimplicit-enum-enum-cast`, which is a more accurate home for it.
`-Wimplicit-enum-enum-cast` is also under `-Wimplicit-int-enum-cast`, as
it is the same incompatibility (the enumeration on the right-hand is
promoted to `int`, so it's an int -> enum conversion).

Fixes #37027
2025-04-29 07:06:08 -04:00