Skip to content

Commit 4b7b5f9

Browse files
committed
Merge from 'main' to 'sycl-web' (9 commits)
CONFLICT (content): Merge conflict in clang/lib/CodeGen/BackendUtil.cpp
2 parents b0d11c6 + 557b064 commit 4b7b5f9

File tree

29 files changed

+3513
-471
lines changed

29 files changed

+3513
-471
lines changed

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,8 +2049,8 @@ the configuration (without a prefix: ``Auto``).
20492049
.. _BreakAfterAttributes:
20502050

20512051
**BreakAfterAttributes** (``AttributeBreakingStyle``) :versionbadge:`clang-format 16` :ref:`<BreakAfterAttributes>`
2052-
Break after a group of C++11 attributes before a function
2053-
declaration/definition name.
2052+
Break after a group of C++11 attributes before a variable/function
2053+
(including constructor/destructor) declaration/definition name.
20542054

20552055
Possible values:
20562056

@@ -2059,6 +2059,10 @@ the configuration (without a prefix: ``Auto``).
20592059

20602060
.. code-block:: c++
20612061

2062+
[[maybe_unused]]
2063+
const int i;
2064+
[[gnu::const]] [[maybe_unused]]
2065+
int j;
20622066
[[nodiscard]]
20632067
inline int f();
20642068
[[gnu::const]] [[nodiscard]]
@@ -2069,6 +2073,9 @@ the configuration (without a prefix: ``Auto``).
20692073

20702074
.. code-block:: c++
20712075

2076+
[[maybe_unused]] const int i;
2077+
[[gnu::const]] [[maybe_unused]]
2078+
int j;
20722079
[[nodiscard]] inline int f();
20732080
[[gnu::const]] [[nodiscard]]
20742081
int g();
@@ -2078,6 +2085,8 @@ the configuration (without a prefix: ``Auto``).
20782085

20792086
.. code-block:: c++
20802087

2088+
[[maybe_unused]] const int i;
2089+
[[gnu::const]] [[maybe_unused]] int j;
20812090
[[nodiscard]] inline int f();
20822091
[[gnu::const]] [[nodiscard]] int g();
20832092

clang/include/clang/Format/Format.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,10 @@ struct FormatStyle {
14281428
enum AttributeBreakingStyle : int8_t {
14291429
/// Always break after attributes.
14301430
/// \code
1431+
/// [[maybe_unused]]
1432+
/// const int i;
1433+
/// [[gnu::const]] [[maybe_unused]]
1434+
/// int j;
14311435
/// [[nodiscard]]
14321436
/// inline int f();
14331437
/// [[gnu::const]] [[nodiscard]]
@@ -1436,21 +1440,26 @@ struct FormatStyle {
14361440
ABS_Always,
14371441
/// Leave the line breaking after attributes as is.
14381442
/// \code
1443+
/// [[maybe_unused]] const int i;
1444+
/// [[gnu::const]] [[maybe_unused]]
1445+
/// int j;
14391446
/// [[nodiscard]] inline int f();
14401447
/// [[gnu::const]] [[nodiscard]]
14411448
/// int g();
14421449
/// \endcode
14431450
ABS_Leave,
14441451
/// Never break after attributes.
14451452
/// \code
1453+
/// [[maybe_unused]] const int i;
1454+
/// [[gnu::const]] [[maybe_unused]] int j;
14461455
/// [[nodiscard]] inline int f();
14471456
/// [[gnu::const]] [[nodiscard]] int g();
14481457
/// \endcode
14491458
ABS_Never,
14501459
};
14511460

1452-
/// Break after a group of C++11 attributes before a function
1453-
/// declaration/definition name.
1461+
/// Break after a group of C++11 attributes before a variable/function
1462+
/// (including constructor/destructor) declaration/definition name.
14541463
/// \version 16
14551464
AttributeBreakingStyle BreakAfterAttributes;
14561465

clang/lib/AST/Expr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5043,10 +5043,10 @@ QualType OMPArraySectionExpr::getBaseOriginalType(const Expr *Base) {
50435043
for (unsigned Cnt = 0; Cnt < ArraySectionCount; ++Cnt) {
50445044
if (OriginalTy->isAnyPointerType())
50455045
OriginalTy = OriginalTy->getPointeeType();
5046-
else {
5047-
assert (OriginalTy->isArrayType());
5046+
else if (OriginalTy->isArrayType())
50485047
OriginalTy = OriginalTy->castAsArrayTypeUnsafe()->getElementType();
5049-
}
5048+
else
5049+
return {};
50505050
}
50515051
return OriginalTy;
50525052
}

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#include "llvm/TargetParser/SubtargetFeature.h"
7171
#include "llvm/TargetParser/Triple.h"
7272
#include "llvm/Transforms/IPO/DeadArgumentElimination.h"
73+
#include "llvm/Transforms/HipStdPar/HipStdPar.h"
7374
#include "llvm/Transforms/IPO/EmbedBitcodePass.h"
7475
#include "llvm/Transforms/IPO/LowerTypeTests.h"
7576
#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
@@ -95,7 +96,6 @@
9596
#include "llvm/Transforms/Scalar/GVN.h"
9697
#include "llvm/Transforms/Scalar/InferAddressSpaces.h"
9798
#include "llvm/Transforms/Scalar/JumpThreading.h"
98-
#include "llvm/Transforms/HipStdPar/HipStdPar.h"
9999
#include "llvm/Transforms/Utils/Debugify.h"
100100
#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
101101
#include "llvm/Transforms/Utils/ModuleUtils.h"

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,6 +2000,10 @@ class AnnotatingParser {
20002000
(!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) {
20012001
Contexts.back().FirstStartOfName = &Current;
20022002
Current.setType(TT_StartOfName);
2003+
if (auto *PrevNonComment = Current.getPreviousNonComment();
2004+
PrevNonComment && PrevNonComment->is(TT_StartOfName)) {
2005+
PrevNonComment->setType(TT_Unknown);
2006+
}
20032007
} else if (Current.is(tok::semi)) {
20042008
// Reset FirstStartOfName after finding a semicolon so that a for loop
20052009
// with multiple increment statements is not confused with a for loop
@@ -3258,7 +3262,7 @@ static bool isFunctionDeclarationName(bool IsCpp, const FormatToken &Current,
32583262
if (Current.is(TT_FunctionDeclarationName))
32593263
return true;
32603264

3261-
if (!Current.Tok.getIdentifierInfo())
3265+
if (!Current.Tok.getIdentifierInfo() || Current.is(TT_CtorDtorDeclName))
32623266
return false;
32633267

32643268
auto skipOperatorName = [](const FormatToken *Next) -> const FormatToken * {
@@ -3441,29 +3445,30 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
34413445
if (AlignArrayOfStructures)
34423446
calculateArrayInitializerColumnList(Line);
34433447

3448+
const bool IsCpp = Style.isCpp();
34443449
bool LineIsFunctionDeclaration = false;
34453450
FormatToken *ClosingParen = nullptr;
34463451
for (FormatToken *Tok = Current, *AfterLastAttribute = nullptr; Tok;
34473452
Tok = Tok->Next) {
34483453
if (Tok->Previous->EndsCppAttributeGroup)
34493454
AfterLastAttribute = Tok;
3450-
if (const bool IsCtorOrDtor = Tok->is(TT_CtorDtorDeclName);
3451-
IsCtorOrDtor ||
3452-
isFunctionDeclarationName(Style.isCpp(), *Tok, Line, ClosingParen)) {
3453-
if (!IsCtorOrDtor) {
3454-
LineIsFunctionDeclaration = true;
3455-
Tok->setFinalizedType(TT_FunctionDeclarationName);
3456-
}
3457-
if (AfterLastAttribute &&
3455+
if (isFunctionDeclarationName(IsCpp, *Tok, Line, ClosingParen)) {
3456+
LineIsFunctionDeclaration = true;
3457+
Tok->setFinalizedType(TT_FunctionDeclarationName);
3458+
}
3459+
if (LineIsFunctionDeclaration ||
3460+
Tok->isOneOf(TT_CtorDtorDeclName, TT_StartOfName)) {
3461+
if (IsCpp && AfterLastAttribute &&
34583462
mustBreakAfterAttributes(*AfterLastAttribute, Style)) {
34593463
AfterLastAttribute->MustBreakBefore = true;
3460-
Line.ReturnTypeWrapped = true;
3464+
if (LineIsFunctionDeclaration)
3465+
Line.ReturnTypeWrapped = true;
34613466
}
34623467
break;
34633468
}
34643469
}
34653470

3466-
if (Style.isCpp()) {
3471+
if (IsCpp) {
34673472
if (!LineIsFunctionDeclaration) {
34683473
// Annotate */&/&& in `operator` function calls as binary operators.
34693474
for (const auto *Tok = Line.First; Tok; Tok = Tok->Next) {

clang/lib/Sema/SemaLookup.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5774,7 +5774,7 @@ void Sema::diagnoseMissingImport(SourceLocation UseLoc, const NamedDecl *Decl,
57745774
llvm::SmallVector<Module*, 8> UniqueModules;
57755775
llvm::SmallDenseSet<Module*, 8> UniqueModuleSet;
57765776
for (auto *M : Modules) {
5777-
if (M->isGlobalModule() || M->isPrivateModule())
5777+
if (M->isExplicitGlobalModule() || M->isPrivateModule())
57785778
continue;
57795779
if (UniqueModuleSet.insert(M).second)
57805780
UniqueModules.push_back(M);
@@ -5806,6 +5806,28 @@ void Sema::diagnoseMissingImport(SourceLocation UseLoc, const NamedDecl *Decl,
58065806

58075807
Modules = UniqueModules;
58085808

5809+
auto GetModuleNameForDiagnostic = [this](const Module *M) -> std::string {
5810+
if (M->isModuleMapModule())
5811+
return M->getFullModuleName();
5812+
5813+
Module *CurrentModule = getCurrentModule();
5814+
5815+
if (M->isImplicitGlobalModule())
5816+
M = M->getTopLevelModule();
5817+
5818+
bool IsInTheSameModule =
5819+
CurrentModule && CurrentModule->getPrimaryModuleInterfaceName() ==
5820+
M->getPrimaryModuleInterfaceName();
5821+
5822+
// If the current module unit is in the same module with M, it is OK to show
5823+
// the partition name. Otherwise, it'll be sufficient to show the primary
5824+
// module name.
5825+
if (IsInTheSameModule)
5826+
return M->getTopLevelModuleName().str();
5827+
else
5828+
return M->getPrimaryModuleInterfaceName().str();
5829+
};
5830+
58095831
if (Modules.size() > 1) {
58105832
std::string ModuleList;
58115833
unsigned N = 0;
@@ -5815,15 +5837,15 @@ void Sema::diagnoseMissingImport(SourceLocation UseLoc, const NamedDecl *Decl,
58155837
ModuleList += "[...]";
58165838
break;
58175839
}
5818-
ModuleList += M->getFullModuleName();
5840+
ModuleList += GetModuleNameForDiagnostic(M);
58195841
}
58205842

58215843
Diag(UseLoc, diag::err_module_unimported_use_multiple)
58225844
<< (int)MIK << Decl << ModuleList;
58235845
} else {
58245846
// FIXME: Add a FixItHint that imports the corresponding module.
58255847
Diag(UseLoc, diag::err_module_unimported_use)
5826-
<< (int)MIK << Decl << Modules[0]->getFullModuleName();
5848+
<< (int)MIK << Decl << GetModuleNameForDiagnostic(Modules[0]);
58275849
}
58285850

58295851
NotePrevious();

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21016,6 +21016,8 @@ Sema::ActOnOpenMPDependClause(const OMPDependClause::DependDataTy &Data,
2101621016
if (OASE) {
2101721017
QualType BaseType =
2101821018
OMPArraySectionExpr::getBaseOriginalType(OASE->getBase());
21019+
if (BaseType.isNull())
21020+
return nullptr;
2101921021
if (const auto *ATy = BaseType->getAsArrayTypeUnsafe())
2102021022
ExprTy = ATy->getElementType();
2102121023
else

clang/test/CXX/module/module.import/p2.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export A f();
2323
//--- Use.cpp
2424
import M;
2525
void test() {
26-
A a; // expected-error {{declaration of 'A' must be imported from module 'M:impl'}}
27-
// expected-error@-1 {{definition of 'A' must be imported from module 'M:impl'}} expected-error@-1 {{}}
26+
A a; // expected-error {{definition of 'A' must be imported from module 'M' before it is required}}
27+
// expected-error@-1 {{definition of 'A' must be imported from module 'M' before it is required}} expected-error@-1 {{}}
2828
// [email protected]:2 {{declaration here is not visible}}
2929
// [email protected]:2 {{definition here is not reachable}} [email protected]:2 {{}}
3030
}
@@ -41,8 +41,8 @@ void test() {
4141
export module B;
4242
import M;
4343
void test() {
44-
A a; // expected-error {{declaration of 'A' must be imported from module 'M:impl'}}
45-
// expected-error@-1 {{definition of 'A' must be imported from module 'M:impl'}} expected-error@-1 {{}}
44+
A a; // expected-error {{declaration of 'A' must be imported from module 'M'}}
45+
// expected-error@-1 {{definition of 'A' must be imported from module 'M'}} expected-error@-1 {{}}
4646
// [email protected]:2 {{declaration here is not visible}}
4747
// [email protected]:2 {{definition here is not reachable}} [email protected]:2 {{}}
4848
}

clang/test/CXX/module/module.reach/ex1.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ export void f(B b = B());
3737
//--- X.cppm
3838
export module X;
3939
import M;
40-
B b3; // expected-error {{definition of 'B' must be imported from module 'M:B' before it is required}} expected-error {{}}
40+
B b3; // expected-error {{definition of 'B' must be imported from module 'M' before it is required}} expected-error {{}}
4141
// expected-note@* {{definition here is not reachable}} expected-note@* {{}}
4242
// FIXME: We should emit an error for unreachable definition of B.
4343
void g() { f(); }
44-
void g1() { f(B()); } // expected-error 1+{{definition of 'B' must be imported from module 'M:B' before it is required}}
44+
void g1() { f(B()); } // expected-error 1+{{definition of 'B' must be imported from module 'M' before it is required}}
4545
// expected-note@* 1+{{definition here is not reachable}}
4646
// [email protected]:5 {{passing argument to parameter 'b' here}}

clang/test/CXX/module/module.reach/p2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ export A f();
1717
//--- UseStrict.cpp
1818
import M;
1919
void test() {
20-
auto a = f(); // expected-error {{definition of 'A' must be imported from module 'M:impl' before it is required}} expected-error{{}}
20+
auto a = f(); // expected-error {{definition of 'A' must be imported from module 'M' before it is required}} expected-error{{}}
2121
// expected-note@* {{definition here is not reachable}} expected-note@* {{}}
2222
}

clang/test/Modules/export-language-linkage.cppm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int use() {
3737
f1();
3838
f2();
3939
f3();
40-
unexported(); // expected-error {{missing '#include'; 'unexported' must be declared before it is used}}
40+
unexported(); // expected-error {{declaration of 'unexported' must be imported from module 'a' before it is required}}
4141
// [email protected]:15 {{declaration here is not visible}}
4242
return foo();
4343
}
@@ -58,6 +58,6 @@ int use() {
5858
}
5959

6060
int use_of_nonexported() {
61-
return h(); // expected-error {{missing '#include'; 'h' must be declared before it is used}}
61+
return h(); // expected-error {{declaration of 'h' must be imported from module 'c' before it is required}}
6262
// [email protected]:4 {{declaration here is not visible}}
6363
}

clang/test/OpenMP/bug69198.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang_cc1 -verify -fsyntax-only -fopenmp -x c %s
2+
3+
int c[-1]; // expected-error {{'c' declared as an array with a negative size}}
4+
5+
void foo (){
6+
#pragma omp task depend(inout: c[:][:])
7+
{
8+
c[0] = 1;
9+
}
10+
}

clang/unittests/Format/FormatTest.cpp

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8479,18 +8479,25 @@ TEST_F(FormatTest, BreaksFunctionDeclarationsWithTrailingTokens) {
84798479
" aaaaaaaaaaaaaaaaaaaaaaaaa));");
84808480
verifyFormat("bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
84818481
" __attribute__((unused));");
8482-
verifyGoogleFormat(
8482+
8483+
Style = getGoogleStyle();
8484+
Style.AttributeMacros.push_back("GUARDED_BY");
8485+
verifyFormat(
84838486
"bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
8484-
" GUARDED_BY(aaaaaaaaaaaa);");
8485-
verifyGoogleFormat(
8487+
" GUARDED_BY(aaaaaaaaaaaa);",
8488+
Style);
8489+
verifyFormat(
84868490
"bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
8487-
" GUARDED_BY(aaaaaaaaaaaa);");
8488-
verifyGoogleFormat(
8491+
" GUARDED_BY(aaaaaaaaaaaa);",
8492+
Style);
8493+
verifyFormat(
84898494
"bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa GUARDED_BY(aaaaaaaaaaaa) =\n"
8490-
" aaaaaaaa::aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;");
8491-
verifyGoogleFormat(
8495+
" aaaaaaaa::aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;",
8496+
Style);
8497+
verifyFormat(
84928498
"bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa GUARDED_BY(aaaaaaaaaaaa) =\n"
8493-
" aaaaaaaaaaaaaaaaaaaaaaaaa;");
8499+
" aaaaaaaaaaaaaaaaaaaaaaaaa;",
8500+
Style);
84948501
}
84958502

84968503
TEST_F(FormatTest, FunctionAnnotations) {
@@ -26192,9 +26199,10 @@ TEST_F(FormatTest, RemoveSemicolon) {
2619226199
}
2619326200

2619426201
TEST_F(FormatTest, BreakAfterAttributes) {
26195-
FormatStyle Style = getLLVMStyle();
26196-
26197-
constexpr StringRef Code("[[nodiscard]] inline int f(int &i);\n"
26202+
constexpr StringRef Code("[[maybe_unused]] const int i;\n"
26203+
"[[foo([[]])]] [[maybe_unused]]\n"
26204+
"int j;\n"
26205+
"[[nodiscard]] inline int f(int &i);\n"
2619826206
"[[foo([[]])]] [[nodiscard]]\n"
2619926207
"int g(int &i);\n"
2620026208
"[[nodiscard]]\n"
@@ -26207,11 +26215,14 @@ TEST_F(FormatTest, BreakAfterAttributes) {
2620726215
" return 1;\n"
2620826216
"}");
2620926217

26218+
FormatStyle Style = getLLVMStyle();
2621026219
EXPECT_EQ(Style.BreakAfterAttributes, FormatStyle::ABS_Leave);
2621126220
verifyNoChange(Code, Style);
2621226221

2621326222
Style.BreakAfterAttributes = FormatStyle::ABS_Never;
26214-
verifyFormat("[[nodiscard]] inline int f(int &i);\n"
26223+
verifyFormat("[[maybe_unused]] const int i;\n"
26224+
"[[foo([[]])]] [[maybe_unused]] int j;\n"
26225+
"[[nodiscard]] inline int f(int &i);\n"
2621526226
"[[foo([[]])]] [[nodiscard]] int g(int &i);\n"
2621626227
"[[nodiscard]] inline int f(int &i) {\n"
2621726228
" i = 1;\n"
@@ -26224,7 +26235,11 @@ TEST_F(FormatTest, BreakAfterAttributes) {
2622426235
Code, Style);
2622526236

2622626237
Style.BreakAfterAttributes = FormatStyle::ABS_Always;
26227-
verifyFormat("[[nodiscard]]\n"
26238+
verifyFormat("[[maybe_unused]]\n"
26239+
"const int i;\n"
26240+
"[[foo([[]])]] [[maybe_unused]]\n"
26241+
"int j;\n"
26242+
"[[nodiscard]]\n"
2622826243
"inline int f(int &i);\n"
2622926244
"[[foo([[]])]] [[nodiscard]]\n"
2623026245
"int g(int &i);\n"

0 commit comments

Comments
 (0)