Skip to content

Commit 7fb36c6

Browse files
committed
Merge remote-tracking branch 'origin/main' into aballman-wg14-n3341
2 parents 83ebaf0 + c3c2f46 commit 7fb36c6

File tree

20 files changed

+522
-40
lines changed

20 files changed

+522
-40
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
/clang/tools/clang-installapi/ @cyndyishida
142142

143143
# ExtractAPI
144-
/clang/**/ExtractAPI @daniel-grumberg
144+
/clang/**/ExtractAPI @daniel-grumberg @QuietMisdreavus
145145

146146
# DWARFLinker, dwarfutil, dsymutil
147147
/llvm/**/DWARFLinker/ @JDevlieghere

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ C2y Feature Support
309309
undefined. Clang has always accepted ``const`` and ``volatile`` qualified
310310
function types by ignoring the qualifiers.
311311

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.
312316

313317
C23 Feature Support
314318
^^^^^^^^^^^^^^^^^^^

clang/test/C/C2y/n3342.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ const volatile f three; /* expected-warning {{'const' qualifier on function type
2323
clang-warning {{'volatile' qualifier on function type 'f' (aka 'int (void)') has no effect and is a Clang extension}}
2424
*/
2525

26+
#if __STDC_VERSION__ >= 201112L
2627
// Atomic types have an explicit constraint making it ill-formed.
2728
_Atomic f four; // both-error {{_Atomic cannot be applied to function type 'f' (aka 'int (void)')}}
29+
#endif
2830

2931
// There's no point to testing 'restrict' because that requires a pointer type.

clang/test/C/C2y/n3346.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
char str3[] = u8"string literal";
50+
char str4[] = { u8"string literal" };
51+
52+
int str5[] = "this doesn't work"; // expected-error {{array initializer must be an initializer list}}
53+
int str6[] = { "this also doesn't work" }; // expected-error {{incompatible pointer to integer conversion initializing 'int' with an expression of type 'char[23]'}}
54+
55+
wchar_t str7[] = L"string literal";
56+
wchar_t str8[] = { L"string literal" };
57+
char16_t str9[] = u"string literal";
58+
char16_t str10[] = { u"string literal" };
59+
char32_t str11[] = U"string literal";
60+
char32_t str12[] = { U"string literal" };
61+
62+
wchar_t str13[] = "nope"; // expected-error {{initializing wide char array with non-wide string literal}}
63+
wchar_t str14[] = { "nope" }; // expected-error-re {{incompatible pointer to integer conversion initializing 'wchar_t' (aka '{{.*}}') with an expression of type 'char[5]'}}
64+
char16_t str15[] = "nope"; // expected-error {{initializing wide char array with non-wide string literal}}
65+
char16_t str16[] = { "nope" }; // expected-error-re {{incompatible pointer to integer conversion initializing 'char16_t' (aka '{{.*}}') with an expression of type 'char[5]'}}
66+
char32_t str17[] = "nope"; // expected-error {{initializing wide char array with non-wide string literal}}
67+
char32_t str18[] = { "nope" }; // expected-error-re {{incompatible pointer to integer conversion initializing 'char32_t' (aka '{{.*}}') with an expression of type 'char[5]'}}
68+
}

clang/www/c_status.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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/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];

0 commit comments

Comments
 (0)