Skip to content

Commit 853f5fe

Browse files
authored
Merge branch 'llvm:main' into m68k_atomic_addr_modes_for_merge
2 parents e5a800c + b70d130 commit 853f5fe

File tree

598 files changed

+124714
-133487
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

598 files changed

+124714
-133487
lines changed

clang/docs/LanguageExtensions.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5975,6 +5975,17 @@ Clang guarantees the following behaviors:
59755975
59765976
Currently, the above extension only applies to C source code, not C++.
59775977
5978+
5979+
Empty Objects in C
5980+
==================
5981+
The declaration of a structure or union type which has no named members is
5982+
undefined behavior (C23 and earlier) or implementation-defined behavior (C2y).
5983+
Clang allows the declaration of a structure or union type with no named members
5984+
in all C language modes. `sizeof` for such a type returns `0`, which is
5985+
different behavior than in C++ (where the size of such an object is typically
5986+
`1`).
5987+
5988+
59785989
Qualified function types in C
59795990
=============================
59805991
Declaring a function with a qualified type in C is undefined behavior (C23 and

clang/docs/ReleaseNotes.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,22 @@ C2y Feature Support
298298
paper adopts Clang's existing practice, so there were no changes to compiler
299299
behavior.
300300

301+
- Implemented support for `N3341 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3341.pdf>`_
302+
which makes empty structure and union objects implementation-defined in C.
303+
``-Wgnu-empty-struct`` will be emitted in C23 and earlier modes because the
304+
behavior is a conforming GNU extension in those modes, but will no longer
305+
have an effect in C2y mode.
306+
301307
- Updated conformance for `N3342 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3342.pdf>`_
302308
which made qualified function types implementation-defined rather than
303309
undefined. Clang has always accepted ``const`` and ``volatile`` qualified
304310
function types by ignoring the qualifiers.
305311

312+
- Updated conformance for `N3346 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3346.pdf>`_
313+
which changes some undefined behavior around initialization to instead be
314+
constraint violations. This paper adopts Clang's existing practice, so there
315+
were no changes to compiler behavior.
316+
306317
C23 Feature Support
307318
^^^^^^^^^^^^^^^^^^^
308319

clang/lib/Sema/SemaDecl.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19365,11 +19365,12 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
1936519365
}
1936619366

1936719367
// Structs without named members are extension in C (C99 6.7.2.1p7),
19368-
// but are accepted by GCC.
19369-
if (NonBitFields == 0 && !getLangOpts().CPlusPlus) {
19370-
Diag(RecLoc, IsEmpty ? diag::ext_empty_struct_union :
19371-
diag::ext_no_named_members_in_struct_union)
19372-
<< Record->isUnion();
19368+
// but are accepted by GCC. In C2y, this became implementation-defined
19369+
// (C2y 6.7.3.2p10).
19370+
if (NonBitFields == 0 && !getLangOpts().CPlusPlus && !getLangOpts().C2y) {
19371+
Diag(RecLoc, IsEmpty ? diag::ext_empty_struct_union
19372+
: diag::ext_no_named_members_in_struct_union)
19373+
<< Record->isUnion();
1937319374
}
1937419375
}
1937519376
} else {

clang/test/C/C2y/n3341.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic %s
2+
// RUN: %clang_cc1 -verify=gnu -Wall -pedantic %s
3+
4+
/* WG14 N3341: Yes
5+
* Slay Some Earthly Demons III
6+
*
7+
* Empty structure and union objects are now implementation-defined.
8+
*/
9+
10+
// expected-no-diagnostics
11+
12+
struct R {}; // gnu-warning {{empty struct is a GNU extension}}
13+
struct S { struct { }; }; // gnu-warning {{empty struct is a GNU extension}}
14+
struct T { int : 0; }; // gnu-warning {{struct without named members is a GNU extension}}
15+
union U {}; // gnu-warning {{empty union is a GNU extension}}
16+

clang/test/C/C2y/n3346.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic -ffreestanding %s
2+
// RUN: %clang_cc1 -verify=expected,ped -Wall -pedantic -ffreestanding %s
3+
4+
/* WG14 N3346: Yes
5+
* Slay Some Earthly Demons VIII
6+
*
7+
* Updates some undefined behavior during initialization to instead be a
8+
* constraint violation.
9+
*/
10+
11+
// The initializer for a scalar shall be a single expression, optionally
12+
// enclosed in braces, or it shall be an empty initializer.
13+
int i = 12, j = {12}, k = {}; // ped-warning {{use of an empty initializer is a C23 extension}}
14+
15+
struct S {
16+
int i;
17+
float f;
18+
int : 0;
19+
char c;
20+
};
21+
22+
void test1(void) {
23+
// The initializer for an object that has structure or union type shall be
24+
// either a single expression that has compatible type or a brace-enclosed
25+
// list of initializers for the elements or named members.
26+
struct S s1 = { 1, 1.2f, 'a' };
27+
struct S s2 = s1;
28+
29+
// Despite being structurally identical to S, T is not compatible with S.
30+
struct T { int i; float f; int : 0; char c; } t;
31+
struct S s3 = t; // expected-error {{initializing 'struct S' with an expression of incompatible type 'struct T'}}
32+
}
33+
34+
void test2(void) {
35+
typedef __WCHAR_TYPE__ wchar_t;
36+
typedef __CHAR16_TYPE__ char16_t;
37+
typedef __CHAR32_TYPE__ char32_t;
38+
39+
// The initializer for an array shall be either a string literal, optionally
40+
// enclosed in braces, or a brace-enclosed list of initializers for the
41+
// elements. An array initialized by character string literal or UTF-8 string
42+
// literal shall have a character type as element type. An array initialized
43+
// with a wide string literal shall have element type compatible with a
44+
// qualified or unqualified wchar_t, char16_t, or char32_t, and the string
45+
// literal shall have the corresponding encoding prefix (L, u, or U,
46+
// respectively).
47+
char str1[] = "string literal";
48+
char str2[] = { "string literal" };
49+
50+
float str5[] = "this doesn't work"; // expected-error {{array initializer must be an initializer list}}
51+
float str6[] = { "this also doesn't work" }; // expected-error {{initializing 'float' with an expression of incompatible type 'char[23]'}}
52+
53+
wchar_t str7[] = L"string literal";
54+
wchar_t str8[] = { L"string literal" };
55+
56+
#if __STDC_VERSION__ >= 201112L
57+
char str3[] = u8"string literal";
58+
char str4[] = { u8"string literal" };
59+
60+
char16_t str9[] = u"string literal";
61+
char16_t str10[] = { u"string literal" };
62+
char32_t str11[] = U"string literal";
63+
char32_t str12[] = { U"string literal" };
64+
#endif
65+
66+
wchar_t str13[] = "nope"; // expected-error {{initializing wide char array with non-wide string literal}}
67+
wchar_t str14[] = { "nope" }; // expected-error-re {{incompatible pointer to integer conversion initializing 'wchar_t' (aka '{{.*}}') with an expression of type 'char[5]'}}
68+
char16_t str15[] = "nope"; // expected-error {{initializing wide char array with non-wide string literal}}
69+
char16_t str16[] = { "nope" }; // expected-error-re {{incompatible pointer to integer conversion initializing 'char16_t' (aka '{{.*}}') with an expression of type 'char[5]'}}
70+
char32_t str17[] = "nope"; // expected-error {{initializing wide char array with non-wide string literal}}
71+
char32_t str18[] = { "nope" }; // expected-error-re {{incompatible pointer to integer conversion initializing 'char32_t' (aka '{{.*}}') with an expression of type 'char[5]'}}
72+
}

clang/www/c_status.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ <h2 id="c2y">C2y implementation status</h2>
191191
<tr>
192192
<td>Slay Some Earthly Demons III</td>
193193
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3341.pdf">N3341</a></td>
194-
<td class="unknown" align="center">Unknown</td>
194+
<td class="full" align="center">Yes</td>
195195
</tr>
196196
<tr>
197197
<td>Slay Some Earthly Demons IV</td>
@@ -211,7 +211,7 @@ <h2 id="c2y">C2y implementation status</h2>
211211
<tr>
212212
<td>Slay Some Earthly Demons VIII</td>
213213
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3346.pdf">N3346</a></td>
214-
<td class="unknown" align="center">Unknown</td>
214+
<td class="full" align="center">Yes</td>
215215
</tr>
216216
<tr>
217217
<td>Introduce complex literals v. 2</td>

llvm/include/llvm/ObjectYAML/ELFYAML.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ struct VerdefEntry {
582582
std::optional<uint16_t> Flags;
583583
std::optional<uint16_t> VersionNdx;
584584
std::optional<uint32_t> Hash;
585+
std::optional<uint16_t> VDAux;
585586
std::vector<StringRef> VerNames;
586587
};
587588

llvm/lib/ObjectYAML/ELFEmitter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,7 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
16551655
VerDef.vd_flags = E.Flags.value_or(0);
16561656
VerDef.vd_ndx = E.VersionNdx.value_or(0);
16571657
VerDef.vd_hash = E.Hash.value_or(0);
1658-
VerDef.vd_aux = sizeof(Elf_Verdef);
1658+
VerDef.vd_aux = E.VDAux.value_or(sizeof(Elf_Verdef));
16591659
VerDef.vd_cnt = E.VerNames.size();
16601660
if (I == Section.Entries->size() - 1)
16611661
VerDef.vd_next = 0;
@@ -1665,13 +1665,13 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
16651665
CBA.write((const char *)&VerDef, sizeof(Elf_Verdef));
16661666

16671667
for (size_t J = 0; J < E.VerNames.size(); ++J, ++AuxCnt) {
1668-
Elf_Verdaux VernAux;
1669-
VernAux.vda_name = DotDynstr.getOffset(E.VerNames[J]);
1668+
Elf_Verdaux VerdAux;
1669+
VerdAux.vda_name = DotDynstr.getOffset(E.VerNames[J]);
16701670
if (J == E.VerNames.size() - 1)
1671-
VernAux.vda_next = 0;
1671+
VerdAux.vda_next = 0;
16721672
else
1673-
VernAux.vda_next = sizeof(Elf_Verdaux);
1674-
CBA.write((const char *)&VernAux, sizeof(Elf_Verdaux));
1673+
VerdAux.vda_next = sizeof(Elf_Verdaux);
1674+
CBA.write((const char *)&VerdAux, sizeof(Elf_Verdaux));
16751675
}
16761676
}
16771677

llvm/lib/ObjectYAML/ELFYAML.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,6 +1921,7 @@ void MappingTraits<ELFYAML::VerdefEntry>::mapping(IO &IO,
19211921
IO.mapOptional("Flags", E.Flags);
19221922
IO.mapOptional("VersionNdx", E.VersionNdx);
19231923
IO.mapOptional("Hash", E.Hash);
1924+
IO.mapOptional("VDAux", E.VDAux);
19241925
IO.mapRequired("Names", E.VerNames);
19251926
}
19261927

llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,7 @@ static void allocateHSAUserSGPRs(CCState &CCInfo,
465465
CCInfo.AllocateReg(DispatchPtrReg);
466466
}
467467

468-
const Module *M = MF.getFunction().getParent();
469-
if (UserSGPRInfo.hasQueuePtr() &&
470-
AMDGPU::getAMDHSACodeObjectVersion(*M) < AMDGPU::AMDHSA_COV5) {
468+
if (UserSGPRInfo.hasQueuePtr()) {
471469
Register QueuePtrReg = Info.addQueuePtr(TRI);
472470
MF.addLiveIn(QueuePtrReg, &AMDGPU::SGPR_64RegClass);
473471
CCInfo.AllocateReg(QueuePtrReg);

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,9 +2376,7 @@ void SITargetLowering::allocateSpecialInputSGPRs(
23762376
if (UserSGPRInfo.hasDispatchPtr())
23772377
allocateSGPR64Input(CCInfo, ArgInfo.DispatchPtr);
23782378

2379-
const Module *M = MF.getFunction().getParent();
2380-
if (UserSGPRInfo.hasQueuePtr() &&
2381-
AMDGPU::getAMDHSACodeObjectVersion(*M) < AMDGPU::AMDHSA_COV5)
2379+
if (UserSGPRInfo.hasQueuePtr())
23822380
allocateSGPR64Input(CCInfo, ArgInfo.QueuePtr);
23832381

23842382
// Implicit arg ptr takes the place of the kernarg segment pointer. This is a
@@ -2429,9 +2427,7 @@ void SITargetLowering::allocateHSAUserSGPRs(CCState &CCInfo,
24292427
CCInfo.AllocateReg(DispatchPtrReg);
24302428
}
24312429

2432-
const Module *M = MF.getFunction().getParent();
2433-
if (UserSGPRInfo.hasQueuePtr() &&
2434-
AMDGPU::getAMDHSACodeObjectVersion(*M) < AMDGPU::AMDHSA_COV5) {
2430+
if (UserSGPRInfo.hasQueuePtr()) {
24352431
Register QueuePtrReg = Info.addQueuePtr(TRI);
24362432
MF.addLiveIn(QueuePtrReg, &AMDGPU::SGPR_64RegClass);
24372433
CCInfo.AllocateReg(QueuePtrReg);

llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,19 @@ static DecodeStatus decodeUImmOperand(MCInst &Inst, uint32_t Imm,
314314
return MCDisassembler::Success;
315315
}
316316

317+
static DecodeStatus decodeUImmLog2XLenOperand(MCInst &Inst, uint32_t Imm,
318+
int64_t Address,
319+
const MCDisassembler *Decoder) {
320+
assert(isUInt<6>(Imm) && "Invalid immediate");
321+
322+
if (!Decoder->getSubtargetInfo().hasFeature(RISCV::Feature64Bit) &&
323+
!isUInt<5>(Imm))
324+
return MCDisassembler::Fail;
325+
326+
Inst.addOperand(MCOperand::createImm(Imm));
327+
return MCDisassembler::Success;
328+
}
329+
317330
template <unsigned N>
318331
static DecodeStatus decodeUImmNonZeroOperand(MCInst &Inst, uint32_t Imm,
319332
int64_t Address,
@@ -323,6 +336,14 @@ static DecodeStatus decodeUImmNonZeroOperand(MCInst &Inst, uint32_t Imm,
323336
return decodeUImmOperand<N>(Inst, Imm, Address, Decoder);
324337
}
325338

339+
static DecodeStatus
340+
decodeUImmLog2XLenNonZeroOperand(MCInst &Inst, uint32_t Imm, int64_t Address,
341+
const MCDisassembler *Decoder) {
342+
if (Imm == 0)
343+
return MCDisassembler::Fail;
344+
return decodeUImmLog2XLenOperand(Inst, Imm, Address, Decoder);
345+
}
346+
326347
template <unsigned N>
327348
static DecodeStatus decodeSImmOperand(MCInst &Inst, uint32_t Imm,
328349
int64_t Address,

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ def uimmlog2xlen : RISCVOp, ImmLeaf<XLenVT, [{
201201
return isUInt<5>(Imm);
202202
}]> {
203203
let ParserMatchClass = UImmLog2XLenAsmOperand;
204-
// TODO: should ensure invalid shamt is rejected when decoding.
205-
let DecoderMethod = "decodeUImmOperand<6>";
204+
let DecoderMethod = "decodeUImmLog2XLenOperand";
206205
let MCOperandPredicate = [{
207206
int64_t Imm;
208207
if (!MCOp.evaluateAsConstantImm(Imm))

llvm/lib/Target/RISCV/RISCVInstrInfoC.td

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ def uimmlog2xlennonzero : RISCVOp, ImmLeaf<XLenVT, [{
2424
return isUInt<5>(Imm) && (Imm != 0);
2525
}]> {
2626
let ParserMatchClass = UImmLog2XLenNonZeroAsmOperand;
27-
// TODO: should ensure invalid shamt is rejected when decoding.
28-
let DecoderMethod = "decodeUImmNonZeroOperand<6>";
27+
let DecoderMethod = "decodeUImmLog2XLenNonZeroOperand";
2928
let OperandType = "OPERAND_UIMMLOG2XLEN_NONZERO";
3029
let MCOperandPredicate = [{
3130
int64_t Imm;

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46183,11 +46183,17 @@ static SDValue combineToExtendBoolVectorInReg(
4618346183
assert((NumElts % EltSizeInBits) == 0 && "Unexpected integer scale");
4618446184
unsigned Scale = NumElts / EltSizeInBits;
4618546185
EVT BroadcastVT = EVT::getVectorVT(*DAG.getContext(), SclVT, EltSizeInBits);
46186-
Vec = DAG.getNode(ISD::SCALAR_TO_VECTOR, DL, BroadcastVT, N00);
46186+
bool UseBroadcast = Subtarget.hasInt256() &&
46187+
(!BroadcastVT.is128BitVector() || isa<LoadSDNode>(N00));
46188+
Vec = UseBroadcast
46189+
? DAG.getSplat(BroadcastVT, DL, N00)
46190+
: DAG.getNode(ISD::SCALAR_TO_VECTOR, DL, BroadcastVT, N00);
4618746191
Vec = DAG.getBitcast(VT, Vec);
4618846192

46189-
for (unsigned i = 0; i != Scale; ++i)
46190-
ShuffleMask.append(EltSizeInBits, i);
46193+
for (unsigned i = 0; i != Scale; ++i) {
46194+
int Offset = UseBroadcast ? (i * EltSizeInBits) : 0;
46195+
ShuffleMask.append(EltSizeInBits, i + Offset);
46196+
}
4619146197
Vec = DAG.getVectorShuffle(VT, DL, Vec, Vec, ShuffleMask);
4619246198
} else if (Subtarget.hasAVX2() && NumElts < EltSizeInBits &&
4619346199
(SclVT == MVT::i8 || SclVT == MVT::i16 || SclVT == MVT::i32)) {
@@ -46196,21 +46202,14 @@ static SDValue combineToExtendBoolVectorInReg(
4619646202
// widened bits won't be used, and this might allow the use of a broadcast
4619746203
// load.
4619846204
assert((EltSizeInBits % NumElts) == 0 && "Unexpected integer scale");
46199-
unsigned Scale = EltSizeInBits / NumElts;
46200-
EVT BroadcastVT =
46201-
EVT::getVectorVT(*DAG.getContext(), SclVT, NumElts * Scale);
46202-
Vec = DAG.getNode(ISD::SCALAR_TO_VECTOR, DL, BroadcastVT, N00);
46203-
ShuffleMask.append(NumElts * Scale, 0);
46204-
Vec = DAG.getVectorShuffle(BroadcastVT, DL, Vec, Vec, ShuffleMask);
46205-
Vec = DAG.getBitcast(VT, Vec);
46205+
EVT BroadcastVT = EVT::getVectorVT(*DAG.getContext(), SclVT,
46206+
(NumElts * EltSizeInBits) / NumElts);
46207+
Vec = DAG.getBitcast(VT, DAG.getSplat(BroadcastVT, DL, N00));
4620646208
} else {
4620746209
// For smaller scalar integers, we can simply any-extend it to the vector
4620846210
// element size (we don't care about the upper bits) and broadcast it to all
4620946211
// elements.
46210-
SDValue Scl = DAG.getAnyExtOrTrunc(N00, DL, SVT);
46211-
Vec = DAG.getNode(ISD::SCALAR_TO_VECTOR, DL, VT, Scl);
46212-
ShuffleMask.append(NumElts, 0);
46213-
Vec = DAG.getVectorShuffle(VT, DL, Vec, Vec, ShuffleMask);
46212+
Vec = DAG.getSplat(VT, DL, DAG.getAnyExtOrTrunc(N00, DL, SVT));
4621446213
}
4621546214

4621646215
// Now, mask the relevant bit in each element.

llvm/lib/Transforms/Scalar/StructurizeCFG.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,6 @@ void StructurizeCFG::insertConditions(bool Loops) {
619619
BasicBlock *SuccFalse = Term->getSuccessor(1);
620620

621621
PhiInserter.Initialize(Boolean, "");
622-
PhiInserter.AddAvailableValue(&Func->getEntryBlock(), Default);
623622
PhiInserter.AddAvailableValue(Loops ? SuccFalse : Parent, Default);
624623

625624
BBPredicates &Preds = Loops ? LoopPreds[SuccFalse] : Predicates[SuccTrue];

llvm/lib/Transforms/Utils/LoopUnroll.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,8 @@ llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
880880
DeadSucc->removePredecessor(Src, /* KeepOneInputPHIs */ true);
881881

882882
// Replace the conditional branch with an unconditional one.
883-
BranchInst::Create(Dest, Term->getIterator());
883+
auto *BI = BranchInst::Create(Dest, Term->getIterator());
884+
BI->setDebugLoc(Term->getDebugLoc());
884885
Term->eraseFromParent();
885886

886887
DTUpdates.emplace_back(DominatorTree::Delete, Src, DeadSucc);

0 commit comments

Comments
 (0)