Skip to content

Commit dcc5bce

Browse files
authored
Merge branch 'main' into fix/125810
2 parents a71e0c3 + 29925b7 commit dcc5bce

File tree

100 files changed

+20198
-14999
lines changed

Some content is hidden

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

100 files changed

+20198
-14999
lines changed

clang-tools-extra/clangd/Preamble.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,10 +627,8 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
627627
return DiagnosticsEngine::Ignored;
628628
switch (Info.getID()) {
629629
case diag::warn_no_newline_eof:
630-
case diag::warn_cxx98_compat_no_newline_eof:
631-
case diag::ext_no_newline_eof:
632630
// If the preamble doesn't span the whole file, drop the no newline at
633-
// eof warnings.
631+
// eof warning.
634632
return Bounds.Size != ContentsBuffer->getBufferSize()
635633
? DiagnosticsEngine::Level::Ignored
636634
: DiagLevel;

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ C2y Feature Support
130130
that ``_Generic`` selection associations may now have ``void`` type, but it
131131
also removes UB with code like ``(void)(void)1;``.
132132
- Implemented `WG14 N3411 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3411.pdf>`_
133-
which allows a source file to not end with a newline character. This is still
134-
reported as a conforming extension in earlier language modes.
133+
which allows a source file to not end with a newline character. Note,
134+
``-pedantic`` will no longer diagnose this in either C or C++ modes. This
135+
feature was adopted as applying to obsolete versions of C in WG14 and as a
136+
defect report in WG21 (CWG787).
135137
- Implemented `WG14 N3353 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3353.htm>_`
136138
which adds the new ``0o`` and ``0O`` ocal literal prefixes and deprecates
137139
octal literals other than ``0`` which do not start with the new prefix. This

clang/include/clang/Basic/DiagnosticFrontendKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def err_test_module_file_extension_version : Error<
266266
"(%3.%4)">;
267267

268268
def warn_eagerly_load_for_standard_cplusplus_modules : Warning<
269-
"the form '-fmodule-file=<BMI-path>' is deprecated for standard C++ named modules;"
269+
"the form '-fmodule-file=<BMI-path>' is deprecated for standard C++ named modules; "
270270
"consider to use '-fmodule-file=<module-name>=<BMI-path>' instead">,
271271
InGroup<DiagGroup<"eager-load-cxx-named-modules">>;
272272

clang/include/clang/Basic/DiagnosticLexKinds.td

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,9 @@ def ext_multi_line_line_comment : Extension<"multi-line // comment">,
5252
def ext_line_comment : Extension<
5353
"// comments are not allowed in this language">,
5454
InGroup<Comment>;
55-
def ext_no_newline_eof : Extension<"no newline at end of file">,
56-
InGroup<NewlineEOF>;
5755
def warn_no_newline_eof : Warning<"no newline at end of file">,
5856
InGroup<NewlineEOF>, DefaultIgnore;
5957

60-
def warn_cxx98_compat_no_newline_eof : Warning<
61-
"C++98 requires newline at end of file">,
62-
InGroup<CXX98CompatPedantic>, DefaultIgnore;
63-
6458
def ext_dollar_in_identifier : Extension<"'$' in identifier">,
6559
InGroup<DiagGroup<"dollar-in-identifier-extension">>;
6660
def ext_charize_microsoft : Extension<

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3654,7 +3654,7 @@ bool Compiler<Emitter>::VisitCXXUuidofExpr(const CXXUuidofExpr *E) {
36543654

36553655
assert(V.isStruct());
36563656
assert(V.getStructNumBases() == 0);
3657-
if (!this->visitAPValueInitializer(V, E))
3657+
if (!this->visitAPValueInitializer(V, E, E->getType()))
36583658
return false;
36593659

36603660
return this->emitFinishInit(E);
@@ -4641,48 +4641,27 @@ bool Compiler<Emitter>::visitAPValue(const APValue &Val, PrimType ValType,
46414641

46424642
template <class Emitter>
46434643
bool Compiler<Emitter>::visitAPValueInitializer(const APValue &Val,
4644-
const Expr *E) {
4645-
4644+
const Expr *E, QualType T) {
46464645
if (Val.isStruct()) {
4647-
const Record *R = this->getRecord(E->getType());
4646+
const Record *R = this->getRecord(T);
46484647
assert(R);
46494648
for (unsigned I = 0, N = Val.getStructNumFields(); I != N; ++I) {
46504649
const APValue &F = Val.getStructField(I);
46514650
const Record::Field *RF = R->getField(I);
4651+
QualType FieldType = RF->Decl->getType();
46524652

4653-
if (F.isInt() || F.isFloat() || F.isLValue() || F.isMemberPointer()) {
4654-
PrimType T = classifyPrim(RF->Decl->getType());
4655-
if (!this->visitAPValue(F, T, E))
4656-
return false;
4657-
if (!this->emitInitField(T, RF->Offset, E))
4658-
return false;
4659-
} else if (F.isArray()) {
4660-
assert(RF->Desc->isPrimitiveArray());
4661-
const auto *ArrType = RF->Decl->getType()->getAsArrayTypeUnsafe();
4662-
PrimType ElemT = classifyPrim(ArrType->getElementType());
4663-
assert(ArrType);
4664-
4665-
if (!this->emitGetPtrField(RF->Offset, E))
4653+
if (std::optional<PrimType> PT = classify(FieldType)) {
4654+
if (!this->visitAPValue(F, *PT, E))
46664655
return false;
4667-
4668-
for (unsigned A = 0, AN = F.getArraySize(); A != AN; ++A) {
4669-
if (!this->visitAPValue(F.getArrayInitializedElt(A), ElemT, E))
4670-
return false;
4671-
if (!this->emitInitElem(ElemT, A, E))
4672-
return false;
4673-
}
4674-
4675-
if (!this->emitPopPtr(E))
4656+
if (!this->emitInitField(*PT, RF->Offset, E))
46764657
return false;
4677-
} else if (F.isStruct() || F.isUnion()) {
4658+
} else {
46784659
if (!this->emitGetPtrField(RF->Offset, E))
46794660
return false;
4680-
if (!this->visitAPValueInitializer(F, E))
4661+
if (!this->visitAPValueInitializer(F, E, FieldType))
46814662
return false;
46824663
if (!this->emitPopPtr(E))
46834664
return false;
4684-
} else {
4685-
assert(false && "I don't think this should be possible");
46864665
}
46874666
}
46884667
return true;
@@ -4696,6 +4675,28 @@ bool Compiler<Emitter>::visitAPValueInitializer(const APValue &Val,
46964675
if (!this->visitAPValue(F, T, E))
46974676
return false;
46984677
return this->emitInitField(T, RF->Offset, E);
4678+
} else if (Val.isArray()) {
4679+
const auto *ArrType = T->getAsArrayTypeUnsafe();
4680+
QualType ElemType = ArrType->getElementType();
4681+
for (unsigned A = 0, AN = Val.getArraySize(); A != AN; ++A) {
4682+
const APValue &Elem = Val.getArrayInitializedElt(A);
4683+
if (std::optional<PrimType> ElemT = classify(ElemType)) {
4684+
if (!this->visitAPValue(Elem, *ElemT, E))
4685+
return false;
4686+
if (!this->emitInitElem(*ElemT, A, E))
4687+
return false;
4688+
} else {
4689+
if (!this->emitConstUint32(A, E))
4690+
return false;
4691+
if (!this->emitArrayElemPtrUint32(E))
4692+
return false;
4693+
if (!this->visitAPValueInitializer(Elem, E, ElemType))
4694+
return false;
4695+
if (!this->emitPopPtr(E))
4696+
return false;
4697+
}
4698+
}
4699+
return true;
46994700
}
47004701
// TODO: Other types.
47014702

@@ -6385,7 +6386,8 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
63856386
return false;
63866387
return this->emitInitGlobal(*T, *Index, E);
63876388
}
6388-
return this->visitAPValueInitializer(TPOD->getValue(), E);
6389+
return this->visitAPValueInitializer(TPOD->getValue(), E,
6390+
TPOD->getType());
63896391
}
63906392
return false;
63916393
}

clang/lib/AST/ByteCode/Compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, bool>,
290290
VarCreationState visitDecl(const VarDecl *VD);
291291
/// Visit an APValue.
292292
bool visitAPValue(const APValue &Val, PrimType ValType, const Expr *E);
293-
bool visitAPValueInitializer(const APValue &Val, const Expr *E);
293+
bool visitAPValueInitializer(const APValue &Val, const Expr *E, QualType T);
294294
/// Visit the given decl as if we have a reference to it.
295295
bool visitDeclRef(const ValueDecl *D, const Expr *E);
296296

clang/lib/Lex/Lexer.cpp

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3187,28 +3187,12 @@ bool Lexer::LexEndOfFile(Token &Result, const char *CurPtr) {
31873187
ConditionalStack.pop_back();
31883188
}
31893189

3190-
// C99 5.1.1.2p2: If the file is non-empty and didn't end in a newline, issue
3191-
// a pedwarn.
3192-
if (CurPtr != BufferStart && (CurPtr[-1] != '\n' && CurPtr[-1] != '\r')) {
3193-
DiagnosticsEngine &Diags = PP->getDiagnostics();
3194-
SourceLocation EndLoc = getSourceLocation(BufferEnd);
3195-
unsigned DiagID = diag::warn_no_newline_eof;
3196-
3197-
if (LangOpts.CPlusPlus11) {
3198-
// C++11 [lex.phases] 2.2 p2
3199-
// Prefer the C++98 pedantic compatibility warning over the generic,
3200-
// non-extension, user-requested "missing newline at EOF" warning.
3201-
if (!Diags.isIgnored(diag::warn_cxx98_compat_no_newline_eof, EndLoc))
3202-
DiagID = diag::warn_cxx98_compat_no_newline_eof;
3203-
} else {
3204-
// This is conforming in C2y, but is an extension in earlier language
3205-
// modes.
3206-
if (!LangOpts.C2y)
3207-
DiagID = diag::ext_no_newline_eof;
3208-
}
3209-
3210-
Diag(BufferEnd, DiagID) << FixItHint::CreateInsertion(EndLoc, "\n");
3211-
}
3190+
// Before C++11 and C2y, a file not ending with a newline was UB. Both
3191+
// standards changed this behavior (as a DR or equivalent), but we still have
3192+
// an opt-in diagnostic to warn about it.
3193+
if (CurPtr != BufferStart && (CurPtr[-1] != '\n' && CurPtr[-1] != '\r'))
3194+
Diag(BufferEnd, diag::warn_no_newline_eof)
3195+
<< FixItHint::CreateInsertion(getSourceLocation(BufferEnd), "\n");
32123196

32133197
BufferPtr = CurPtr;
32143198

clang/test/AST/ByteCode/cxx20.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,3 +964,28 @@ namespace PseudoDtor {
964964
static_assert(f3() == 0);
965965
#endif
966966
}
967+
968+
namespace NastyChar {
969+
struct nasty_char {
970+
template <typename T> friend auto operator<=>(T, T) = delete;
971+
template <typename T> friend void operator+(T &&) = delete;
972+
template <typename T> friend void operator-(T &&) = delete;
973+
template <typename T> friend void operator&(T &&) = delete;
974+
975+
char c;
976+
};
977+
978+
979+
template <unsigned N> struct ToNastyChar {
980+
constexpr ToNastyChar(const char (&r)[N]) {
981+
for (unsigned I = 0; I != N; ++I)
982+
text[I] = nasty_char{r[I]};
983+
}
984+
nasty_char text[N];
985+
};
986+
987+
template <unsigned N> ToNastyChar(const char (&)[N]) -> ToNastyChar<N>;
988+
989+
template <ToNastyChar t> constexpr auto to_nasty_char() { return t; }
990+
constexpr auto result = to_nasty_char<"12345">();
991+
}

clang/test/C/C2y/n3411.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// RUN: %clang_cc1 -verify=good -std=c2y -Wall -pedantic %s
22
// RUN: %clang_cc1 -verify -Wnewline-eof -std=c2y -Wall -pedantic %s
3-
// RUN: %clang_cc1 -verify -std=c23 -Wall -pedantic %s
3+
// RUN: %clang_cc1 -verify=good -std=c23 -Wall -pedantic %s
44
// RUN: %clang_cc1 -verify=good -std=c23 %s
5+
// RUN: %clang_cc1 -verify -Wnewline-eof -std=c23 %s
56

67
/* WG14 N3411: Yes
78
* Slay Some Earthly Demons XII

clang/test/CXX/drs/cwg787.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2+
// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3+
// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4+
// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5+
// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
6+
// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++23 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
7+
// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++2c %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
8+
// expected-no-diagnostics
9+
10+
// This file intentionally does not end with a newline. CWG787 made this
11+
// well-defined behavior.
12+
13+
// cwg787: 21

0 commit comments

Comments
 (0)