Skip to content

Commit 5a5152f

Browse files
committed
Merge remote-tracking branch 'upstream/release/18.x' into rustc/18.1-2024-05-19
2 parents b31c30a + 768118d commit 5a5152f

File tree

8 files changed

+68
-42
lines changed

8 files changed

+68
-42
lines changed

clang/lib/Format/TokenAnnotator.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -5159,9 +5159,11 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
51595159
return true;
51605160
if (Left.IsUnterminatedLiteral)
51615161
return true;
5162-
if (Right.is(tok::lessless) && Right.Next && Left.is(tok::string_literal) &&
5163-
Right.Next->is(tok::string_literal)) {
5164-
return true;
5162+
if (const auto *BeforeLeft = Left.Previous, *AfterRight = Right.Next;
5163+
BeforeLeft && BeforeLeft->is(tok::lessless) &&
5164+
Left.is(tok::string_literal) && Right.is(tok::lessless) && AfterRight &&
5165+
AfterRight->is(tok::string_literal)) {
5166+
return Right.NewlinesBefore > 0;
51655167
}
51665168
if (Right.is(TT_RequiresClause)) {
51675169
switch (Style.RequiresClausePosition) {

clang/lib/Format/UnwrappedLineParser.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -1185,12 +1185,6 @@ void UnwrappedLineParser::parsePPDefine() {
11851185
return;
11861186
}
11871187

1188-
if (FormatTok->is(tok::identifier) &&
1189-
Tokens->peekNextToken()->is(tok::colon)) {
1190-
nextToken();
1191-
nextToken();
1192-
}
1193-
11941188
// Errors during a preprocessor directive can only affect the layout of the
11951189
// preprocessor directive, and thus we ignore them. An alternative approach
11961190
// would be to use the same approach we use on the file level (no
@@ -1671,7 +1665,8 @@ void UnwrappedLineParser::parseStructuralElement(
16711665
if (!Style.isJavaScript() && !Style.isVerilog() && !Style.isTableGen() &&
16721666
Tokens->peekNextToken()->is(tok::colon) && !Line->MustBeDeclaration) {
16731667
nextToken();
1674-
Line->Tokens.begin()->Tok->MustBreakBefore = true;
1668+
if (!Line->InMacroBody || CurrentLines->size() > 1)
1669+
Line->Tokens.begin()->Tok->MustBreakBefore = true;
16751670
FormatTok->setFinalizedType(TT_GotoLabelColon);
16761671
parseLabel(!Style.IndentGotoLabels);
16771672
if (HasLabel)

clang/unittests/Format/FormatTest.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -3118,6 +3118,7 @@ TEST_F(FormatTest, FormatsLabels) {
31183118
" g();\n"
31193119
" }\n"
31203120
"}");
3121+
31213122
FormatStyle Style = getLLVMStyle();
31223123
Style.IndentGotoLabels = false;
31233124
verifyFormat("void f() {\n"
@@ -3157,6 +3158,13 @@ TEST_F(FormatTest, FormatsLabels) {
31573158
" }\n"
31583159
"}",
31593160
Style);
3161+
3162+
Style.ColumnLimit = 15;
3163+
verifyFormat("#define FOO \\\n"
3164+
"label: \\\n"
3165+
" break;",
3166+
Style);
3167+
31603168
// The opening brace may either be on the same unwrapped line as the colon or
31613169
// on a separate one. The formatter should recognize both.
31623170
Style = getLLVMStyle();
@@ -10426,6 +10434,17 @@ TEST_F(FormatTest, KeepStringLabelValuePairsOnALine) {
1042610434
" bbbbbbbbbbbbbbbbbbbbbbb);");
1042710435
}
1042810436

10437+
TEST_F(FormatTest, WrapBeforeInsertionOperatorbetweenStringLiterals) {
10438+
verifyFormat("QStringList() << \"foo\" << \"bar\";");
10439+
10440+
verifyNoChange("QStringList() << \"foo\"\n"
10441+
" << \"bar\";");
10442+
10443+
verifyFormat("log_error(log, \"foo\" << \"bar\");",
10444+
"log_error(log, \"foo\"\n"
10445+
" << \"bar\");");
10446+
}
10447+
1042910448
TEST_F(FormatTest, UnderstandsEquals) {
1043010449
verifyFormat(
1043110450
"aaaaaaaaaaaaaaaaa =\n"

clang/unittests/Format/TokenAnnotatorTest.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -2353,15 +2353,28 @@ TEST_F(TokenAnnotatorTest, UnderstandsLabels) {
23532353
auto Tokens = annotate("{ x: break; }");
23542354
ASSERT_EQ(Tokens.size(), 7u) << Tokens;
23552355
EXPECT_TOKEN(Tokens[2], tok::colon, TT_GotoLabelColon);
2356+
23562357
Tokens = annotate("{ case x: break; }");
23572358
ASSERT_EQ(Tokens.size(), 8u) << Tokens;
23582359
EXPECT_TOKEN(Tokens[3], tok::colon, TT_CaseLabelColon);
2360+
23592361
Tokens = annotate("{ x: { break; } }");
23602362
ASSERT_EQ(Tokens.size(), 9u) << Tokens;
23612363
EXPECT_TOKEN(Tokens[2], tok::colon, TT_GotoLabelColon);
2364+
23622365
Tokens = annotate("{ case x: { break; } }");
23632366
ASSERT_EQ(Tokens.size(), 10u) << Tokens;
23642367
EXPECT_TOKEN(Tokens[3], tok::colon, TT_CaseLabelColon);
2368+
2369+
Tokens = annotate("#define FOO label:");
2370+
ASSERT_EQ(Tokens.size(), 6u) << Tokens;
2371+
EXPECT_TOKEN(Tokens[4], tok::colon, TT_GotoLabelColon);
2372+
2373+
Tokens = annotate("#define FOO \\\n"
2374+
"label: \\\n"
2375+
" break;");
2376+
ASSERT_EQ(Tokens.size(), 8u) << Tokens;
2377+
EXPECT_TOKEN(Tokens[4], tok::colon, TT_GotoLabelColon);
23652378
}
23662379

23672380
TEST_F(TokenAnnotatorTest, UnderstandsNestedBlocks) {

llvm/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if(NOT DEFINED LLVM_VERSION_MINOR)
2222
set(LLVM_VERSION_MINOR 1)
2323
endif()
2424
if(NOT DEFINED LLVM_VERSION_PATCH)
25-
set(LLVM_VERSION_PATCH 6)
25+
set(LLVM_VERSION_PATCH 7)
2626
endif()
2727
if(NOT DEFINED LLVM_VERSION_SUFFIX)
2828
set(LLVM_VERSION_SUFFIX)

llvm/lib/Target/PowerPC/PPCMergeStringPool.cpp

+7-30
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,6 @@ bool PPCMergeStringPool::mergeModuleStringPool(Module &M) {
290290
return true;
291291
}
292292

293-
static bool userHasOperand(User *TheUser, GlobalVariable *GVOperand) {
294-
for (Value *Op : TheUser->operands())
295-
if (Op == GVOperand)
296-
return true;
297-
return false;
298-
}
299-
300293
// For pooled strings we need to add the offset into the pool for each string.
301294
// This is done by adding a Get Element Pointer (GEP) before each user. This
302295
// function adds the GEP.
@@ -307,29 +300,13 @@ void PPCMergeStringPool::replaceUsesWithGEP(GlobalVariable *GlobalToReplace,
307300
Indices.push_back(ConstantInt::get(Type::getInt32Ty(*Context), 0));
308301
Indices.push_back(ConstantInt::get(Type::getInt32Ty(*Context), ElementIndex));
309302

310-
// Need to save a temporary copy of each user list because we remove uses
311-
// as we replace them.
312-
SmallVector<User *> Users;
313-
for (User *CurrentUser : GlobalToReplace->users())
314-
Users.push_back(CurrentUser);
315-
316-
for (User *CurrentUser : Users) {
317-
// The user was not found so it must have been replaced earlier.
318-
if (!userHasOperand(CurrentUser, GlobalToReplace))
319-
continue;
320-
321-
// We cannot replace operands in globals so we ignore those.
322-
if (isa<GlobalValue>(CurrentUser))
323-
continue;
324-
325-
Constant *ConstGEP = ConstantExpr::getInBoundsGetElementPtr(
326-
PooledStructType, GPool, Indices);
327-
LLVM_DEBUG(dbgs() << "Replacing this global:\n");
328-
LLVM_DEBUG(GlobalToReplace->dump());
329-
LLVM_DEBUG(dbgs() << "with this:\n");
330-
LLVM_DEBUG(ConstGEP->dump());
331-
GlobalToReplace->replaceAllUsesWith(ConstGEP);
332-
}
303+
Constant *ConstGEP =
304+
ConstantExpr::getInBoundsGetElementPtr(PooledStructType, GPool, Indices);
305+
LLVM_DEBUG(dbgs() << "Replacing this global:\n");
306+
LLVM_DEBUG(GlobalToReplace->dump());
307+
LLVM_DEBUG(dbgs() << "with this:\n");
308+
LLVM_DEBUG(ConstGEP->dump());
309+
GlobalToReplace->replaceAllUsesWith(ConstGEP);
333310
}
334311

335312
} // namespace
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu < %s | FileCheck %s
3+
4+
@g = private constant [4 x i32] [i32 122, i32 67, i32 35, i32 56]
5+
@g2 = private constant [1 x i64] [i64 1], align 8
6+
7+
define void @test(ptr %p, ptr %p2) {
8+
; CHECK-LABEL: test:
9+
; CHECK: # %bb.0:
10+
; CHECK-NEXT: addis 5, 2, .L__ModuleStringPool@toc@ha
11+
; CHECK-NEXT: addi 5, 5, .L__ModuleStringPool@toc@l
12+
; CHECK-NEXT: addi 6, 5, 12
13+
; CHECK-NEXT: std 6, 0(3)
14+
; CHECK-NEXT: addi 3, 5, 16
15+
; CHECK-NEXT: std 3, 0(4)
16+
; CHECK-NEXT: blr
17+
store ptr getelementptr inbounds ([4 x i32], ptr @g, i64 0, i64 1), ptr %p
18+
store ptr getelementptr inbounds ([4 x i32], ptr @g, i64 0, i64 2), ptr %p2
19+
ret void
20+
}

llvm/utils/lit/lit/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
__author__ = "Daniel Dunbar"
44
__email__ = "[email protected]"
5-
__versioninfo__ = (18, 1, 6)
5+
__versioninfo__ = (18, 1, 7)
66
__version__ = ".".join(str(v) for v in __versioninfo__) + "dev"
77

88
__all__ = []

0 commit comments

Comments
 (0)