Skip to content

Commit ed0e4c9

Browse files
committed
Merge branch 'main' into rh/negative-extract-slice-canon
2 parents efcb377 + 67f9cd4 commit ed0e4c9

File tree

309 files changed

+5749
-2837
lines changed

Some content is hidden

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

309 files changed

+5749
-2837
lines changed

.github/workflows/libcxx-build-and-test.yaml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ env:
5050
jobs:
5151
stage1:
5252
if: github.repository_owner == 'llvm'
53-
runs-on:
54-
group: libcxx-runners-8
53+
runs-on: libcxx-runners-8-set
5554
continue-on-error: false
5655
strategy:
5756
fail-fast: true
@@ -89,8 +88,7 @@ jobs:
8988
**/crash_diagnostics/*
9089
stage2:
9190
if: github.repository_owner == 'llvm'
92-
runs-on:
93-
group: libcxx-runners-8
91+
runs-on: libcxx-runners-8-set
9492
needs: [ stage1 ]
9593
continue-on-error: false
9694
strategy:
@@ -169,27 +167,26 @@ jobs:
169167
'benchmarks',
170168
'bootstrapping-build'
171169
]
172-
machine: [ 'libcxx-runners-8' ]
170+
machine: [ 'libcxx-runners-8-set' ]
173171
std_modules: [ 'OFF' ]
174172
include:
175173
- config: 'generic-cxx26'
176-
machine: libcxx-runners-8
174+
machine: libcxx-runners-8-set
177175
std_modules: 'ON'
178176
- config: 'generic-asan'
179-
machine: libcxx-runners-8
177+
machine: libcxx-runners-8-set
180178
std_modules: 'OFF'
181179
- config: 'generic-tsan'
182-
machine: libcxx-runners-8
180+
machine: libcxx-runners-8-set
183181
std_modules: 'OFF'
184182
- config: 'generic-ubsan'
185-
machine: libcxx-runners-8
183+
machine: libcxx-runners-8-set
186184
std_modules: 'OFF'
187185
# Use a larger machine for MSAN to avoid timeout and memory allocation issues.
188186
- config: 'generic-msan'
189-
machine: libcxx-runners-32
187+
machine: libcxx-runners-32-set
190188
std_modules: 'OFF'
191-
runs-on:
192-
group: ${{ matrix.machine }}
189+
runs-on: ${{ matrix.machine }}
193190
steps:
194191
- uses: actions/checkout@v4
195192
- name: ${{ matrix.config }}

.mailmap

Lines changed: 1 addition & 0 deletions

clang-tools-extra/clangd/InlayHints.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,31 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
589589
return true;
590590
}
591591

592+
// Carefully recurse into PseudoObjectExprs, which typically incorporate
593+
// a syntactic expression and several semantic expressions.
594+
bool TraversePseudoObjectExpr(PseudoObjectExpr *E) {
595+
Expr *SyntacticExpr = E->getSyntacticForm();
596+
if (isa<CallExpr>(SyntacticExpr))
597+
// Since the counterpart semantics usually get the identical source
598+
// locations as the syntactic one, visiting those would end up presenting
599+
// confusing hints e.g., __builtin_dump_struct.
600+
// Thus, only traverse the syntactic forms if this is written as a
601+
// CallExpr. This leaves the door open in case the arguments in the
602+
// syntactic form could possibly get parameter names.
603+
return RecursiveASTVisitor<InlayHintVisitor>::TraverseStmt(SyntacticExpr);
604+
// We don't want the hints for some of the MS property extensions.
605+
// e.g.
606+
// struct S {
607+
// __declspec(property(get=GetX, put=PutX)) int x[];
608+
// void PutX(int y);
609+
// void Work(int y) { x = y; } // Bad: `x = y: y`.
610+
// };
611+
if (isa<BinaryOperator>(SyntacticExpr))
612+
return true;
613+
// FIXME: Handle other forms of a pseudo object expression.
614+
return RecursiveASTVisitor<InlayHintVisitor>::TraversePseudoObjectExpr(E);
615+
}
616+
592617
bool VisitCallExpr(CallExpr *E) {
593618
if (!Cfg.InlayHints.Parameters)
594619
return true;

clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,8 @@ TEST(DesignatorHints, NoCrash) {
17091709
void test() {
17101710
Foo f{A(), $b[[1]]};
17111711
}
1712-
)cpp", ExpectedHint{".b=", "b"});
1712+
)cpp",
1713+
ExpectedHint{".b=", "b"});
17131714
}
17141715

17151716
TEST(InlayHints, RestrictRange) {
@@ -1724,6 +1725,38 @@ TEST(InlayHints, RestrictRange) {
17241725
ElementsAre(labelIs(": int"), labelIs(": char")));
17251726
}
17261727

1728+
TEST(ParameterHints, PseudoObjectExpr) {
1729+
Annotations Code(R"cpp(
1730+
struct S {
1731+
__declspec(property(get=GetX, put=PutX)) int x[];
1732+
int GetX(int y, int z) { return 42 + y; }
1733+
void PutX(int) { }
1734+
1735+
// This is a PseudoObjectExpression whose syntactic form is a binary
1736+
// operator.
1737+
void Work(int y) { x = y; } // Not `x = y: y`.
1738+
};
1739+
1740+
int printf(const char *Format, ...);
1741+
1742+
int main() {
1743+
S s;
1744+
__builtin_dump_struct(&s, printf); // Not `Format: __builtin_dump_struct()`
1745+
printf($Param[["Hello, %d"]], 42); // Normal calls are not affected.
1746+
// This builds a PseudoObjectExpr, but here it's useful for showing the
1747+
// arguments from the semantic form.
1748+
return s.x[ $one[[1]] ][ $two[[2]] ]; // `x[y: 1][z: 2]`
1749+
}
1750+
)cpp");
1751+
auto TU = TestTU::withCode(Code.code());
1752+
TU.ExtraArgs.push_back("-fms-extensions");
1753+
auto AST = TU.build();
1754+
EXPECT_THAT(inlayHints(AST, std::nullopt),
1755+
ElementsAre(HintMatcher(ExpectedHint{"Format: ", "Param"}, Code),
1756+
HintMatcher(ExpectedHint{"y: ", "one"}, Code),
1757+
HintMatcher(ExpectedHint{"z: ", "two"}, Code)));
1758+
}
1759+
17271760
TEST(ParameterHints, ArgPacksAndConstructors) {
17281761
assertParameterHints(
17291762
R"cpp(

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,8 @@ Bug Fixes in This Version
651651
- Fixed false positive error emitted by clang when performing qualified name
652652
lookup and the current class instantiation has dependent bases.
653653
Fixes (`#13826 <https://github.com/llvm/llvm-project/issues/13826>`_)
654+
- Clang's ``-Wchar-subscripts`` no longer warns on chars whose values are known non-negative constants.
655+
Fixes (`#18763 <https://github.com/llvm/llvm-project/issues/18763>`_)
654656

655657
Bug Fixes to Compiler Builtins
656658
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/docs/UsersManual.rst

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,9 +2348,10 @@ differences between the two:
23482348

23492349
1. Profile data generated with one cannot be used by the other, and there is no
23502350
conversion tool that can convert one to the other. So, a profile generated
2351-
via ``-fprofile-instr-generate`` must be used with ``-fprofile-instr-use``.
2352-
Similarly, sampling profiles generated by external profilers must be
2353-
converted and used with ``-fprofile-sample-use``.
2351+
via ``-fprofile-generate`` or ``-fprofile-instr-generate`` must be used with
2352+
``-fprofile-use`` or ``-fprofile-instr-use``. Similarly, sampling profiles
2353+
generated by external profilers must be converted and used with ``-fprofile-sample-use``
2354+
or ``-fauto-profile``.
23542355

23552356
2. Instrumentation profile data can be used for code coverage analysis and
23562357
optimization.
@@ -2598,6 +2599,8 @@ Of those, 31,977 were spent inside the body of ``bar``. The last line
25982599
of the profile (``2: 0``) corresponds to line 2 inside ``main``. No
25992600
samples were collected there.
26002601

2602+
.. _prof_instr:
2603+
26012604
Profiling with Instrumentation
26022605
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26032606

@@ -2607,11 +2610,25 @@ overhead during the profiling, but it provides more detailed results than a
26072610
sampling profiler. It also provides reproducible results, at least to the
26082611
extent that the code behaves consistently across runs.
26092612

2613+
Clang supports two types of instrumentation: frontend-based and IR-based.
2614+
Frontend-based instrumentation can be enabled with the option ``-fprofile-instr-generate``,
2615+
and IR-based instrumentation can be enabled with the option ``-fprofile-generate``.
2616+
For best performance with PGO, IR-based instrumentation should be used. It has
2617+
the benefits of lower instrumentation overhead, smaller raw profile size, and
2618+
better runtime performance. Frontend-based instrumentation, on the other hand,
2619+
has better source correlation, so it should be used with source line-based
2620+
coverage testing.
2621+
2622+
The flag ``-fcs-profile-generate`` also instruments programs using the same
2623+
instrumentation method as ``-fprofile-generate``. However, it performs a
2624+
post-inline late instrumentation and can produce context-sensitive profiles.
2625+
2626+
26102627
Here are the steps for using profile guided optimization with
26112628
instrumentation:
26122629

26132630
1. Build an instrumented version of the code by compiling and linking with the
2614-
``-fprofile-instr-generate`` option.
2631+
``-fprofile-generate`` or ``-fprofile-instr-generate`` option.
26152632

26162633
.. code-block:: console
26172634
@@ -2674,8 +2691,8 @@ instrumentation:
26742691
Note that this step is necessary even when there is only one "raw" profile,
26752692
since the merge operation also changes the file format.
26762693

2677-
4. Build the code again using the ``-fprofile-instr-use`` option to specify the
2678-
collected profile data.
2694+
4. Build the code again using the ``-fprofile-use`` or ``-fprofile-instr-use``
2695+
option to specify the collected profile data.
26792696

26802697
.. code-block:: console
26812698
@@ -2685,13 +2702,10 @@ instrumentation:
26852702
profile. As you make changes to your code, clang may no longer be able to
26862703
use the profile data. It will warn you when this happens.
26872704

2688-
Profile generation using an alternative instrumentation method can be
2689-
controlled by the GCC-compatible flags ``-fprofile-generate`` and
2690-
``-fprofile-use``. Although these flags are semantically equivalent to
2691-
their GCC counterparts, they *do not* handle GCC-compatible profiles.
2692-
They are only meant to implement GCC's semantics with respect to
2693-
profile creation and use. Flag ``-fcs-profile-generate`` also instruments
2694-
programs using the same instrumentation method as ``-fprofile-generate``.
2705+
Note that ``-fprofile-use`` option is semantically equivalent to
2706+
its GCC counterpart, it *does not* handle profile formats produced by GCC.
2707+
Both ``-fprofile-use`` and ``-fprofile-instr-use`` accept profiles in the
2708+
indexed format, regardeless whether it is produced by frontend or the IR pass.
26952709

26962710
.. option:: -fprofile-generate[=<dirname>]
26972711

@@ -4401,13 +4415,21 @@ Execute ``clang-cl /?`` to see a list of supported options:
44014415
Instrument only functions from files where names don't match all the regexes separated by a semi-colon
44024416
-fprofile-filter-files=<value>
44034417
Instrument only functions from files where names match any regex separated by a semi-colon
4404-
-fprofile-instr-generate=<file>
4405-
Generate instrumented code to collect execution counts into <file>
4418+
-fprofile-generate=<dirname>
4419+
Generate instrumented code to collect execution counts into a raw profile file in the directory specified by the argument. The filename uses default_%m.profraw pattern
4420+
(overridden by LLVM_PROFILE_FILE env var)
4421+
-fprofile-generate
4422+
Generate instrumented code to collect execution counts into default_%m.profraw file
4423+
(overridden by '=' form of option or LLVM_PROFILE_FILE env var)
4424+
-fprofile-instr-generate=<file_name_pattern>
4425+
Generate instrumented code to collect execution counts into the file whose name pattern is specified as the argument
44064426
(overridden by LLVM_PROFILE_FILE env var)
44074427
-fprofile-instr-generate
44084428
Generate instrumented code to collect execution counts into default.profraw file
44094429
(overridden by '=' form of option or LLVM_PROFILE_FILE env var)
44104430
-fprofile-instr-use=<value>
4431+
Use instrumentation data for coverage testing or profile-guided optimization
4432+
-fprofile-use=<value>
44114433
Use instrumentation data for profile-guided optimization
44124434
-fprofile-remapping-file=<file>
44134435
Use the remappings described in <file> to match the profile data against names in the program
@@ -4569,7 +4591,7 @@ clang-cl supports several features that require runtime library support:
45694591
- Address Sanitizer (ASan): ``-fsanitize=address``
45704592
- Undefined Behavior Sanitizer (UBSan): ``-fsanitize=undefined``
45714593
- Code coverage: ``-fprofile-instr-generate -fcoverage-mapping``
4572-
- Profile Guided Optimization (PGO): ``-fprofile-instr-generate``
4594+
- Profile Guided Optimization (PGO): ``-fprofile-generate``
45734595
- Certain math operations (int128 division) require the builtins library
45744596

45754597
In order to use these features, the user must link the right runtime libraries

clang/include/clang/Basic/AttrDocs.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7547,7 +7547,7 @@ For example,
75477547
Task<int> foo() { return increment(1); } // Error. foo is not a coroutine.
75487548

75497549
// Fine for a coroutine wrapper to return a CRT.
7550-
Task<int> [[clang::coro_wrapper]] foo() { return increment(1); }
7550+
[[clang::coro_wrapper]] Task<int> foo() { return increment(1); }
75517551

75527552
void bar() {
75537553
// Invalid. This intantiates a function which returns a CRT but is not marked as

clang/lib/CodeGen/CodeGenTBAA.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type *Ty) {
342342
// field. Virtual bases are more complex and omitted, but avoid an
343343
// incomplete view for NewStructPathTBAA.
344344
if (CodeGenOpts.NewStructPathTBAA && CXXRD->getNumVBases() != 0)
345-
return BaseTypeMetadataCache[Ty] = nullptr;
345+
return nullptr;
346346
for (const CXXBaseSpecifier &B : CXXRD->bases()) {
347347
if (B.isVirtual())
348348
continue;
@@ -354,7 +354,7 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type *Ty) {
354354
? getBaseTypeInfo(BaseQTy)
355355
: getTypeInfo(BaseQTy);
356356
if (!TypeNode)
357-
return BaseTypeMetadataCache[Ty] = nullptr;
357+
return nullptr;
358358
uint64_t Offset = Layout.getBaseClassOffset(BaseRD).getQuantity();
359359
uint64_t Size =
360360
Context.getASTRecordLayout(BaseRD).getDataSize().getQuantity();
@@ -378,7 +378,7 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type *Ty) {
378378
llvm::MDNode *TypeNode = isValidBaseType(FieldQTy) ?
379379
getBaseTypeInfo(FieldQTy) : getTypeInfo(FieldQTy);
380380
if (!TypeNode)
381-
return BaseTypeMetadataCache[Ty] = nullptr;
381+
return nullptr;
382382

383383
uint64_t BitOffset = Layout.getFieldOffset(Field->getFieldIndex());
384384
uint64_t Offset = Context.toCharUnitsFromBits(BitOffset).getQuantity();
@@ -418,14 +418,20 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfo(QualType QTy) {
418418
return nullptr;
419419

420420
const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
421-
if (llvm::MDNode *N = BaseTypeMetadataCache[Ty])
422-
return N;
423421

424-
// Note that the following helper call is allowed to add new nodes to the
425-
// cache, which invalidates all its previously obtained iterators. So we
426-
// first generate the node for the type and then add that node to the cache.
422+
// nullptr is a valid value in the cache, so use find rather than []
423+
auto I = BaseTypeMetadataCache.find(Ty);
424+
if (I != BaseTypeMetadataCache.end())
425+
return I->second;
426+
427+
// First calculate the metadata, before recomputing the insertion point, as
428+
// the helper can recursively call us.
427429
llvm::MDNode *TypeNode = getBaseTypeInfoHelper(Ty);
428-
return BaseTypeMetadataCache[Ty] = TypeNode;
430+
LLVM_ATTRIBUTE_UNUSED auto inserted =
431+
BaseTypeMetadataCache.insert({Ty, TypeNode});
432+
assert(inserted.second && "BaseType metadata was already inserted");
433+
434+
return TypeNode;
429435
}
430436

431437
llvm::MDNode *CodeGenTBAA::getAccessTagInfo(TBAAAccessInfo Info) {

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,30 @@ void Flang::AddAArch64TargetArgs(const ArgList &Args,
205205
}
206206
}
207207

208+
static void addVSDefines(const ToolChain &TC, const ArgList &Args,
209+
ArgStringList &CmdArgs) {
210+
211+
unsigned ver = 0;
212+
const VersionTuple vt = TC.computeMSVCVersion(nullptr, Args);
213+
ver = vt.getMajor() * 10000000 + vt.getMinor().value_or(0) * 100000 +
214+
vt.getSubminor().value_or(0);
215+
CmdArgs.push_back(Args.MakeArgString("-D_MSC_VER=" + Twine(ver / 100000)));
216+
CmdArgs.push_back(Args.MakeArgString("-D_MSC_FULL_VER=" + Twine(ver)));
217+
CmdArgs.push_back(Args.MakeArgString("-D_WIN32"));
218+
219+
llvm::Triple triple = TC.getTriple();
220+
if (triple.isAArch64()) {
221+
CmdArgs.push_back("-D_M_ARM64=1");
222+
} else if (triple.isX86() && triple.isArch32Bit()) {
223+
CmdArgs.push_back("-D_M_IX86=600");
224+
} else if (triple.isX86() && triple.isArch64Bit()) {
225+
CmdArgs.push_back("-D_M_X64=100");
226+
} else {
227+
llvm_unreachable(
228+
"Flang on Windows only supports X86_32, X86_64 and AArch64");
229+
}
230+
}
231+
208232
static void processVSRuntimeLibrary(const ToolChain &TC, const ArgList &Args,
209233
ArgStringList &CmdArgs) {
210234
assert(TC.getTriple().isKnownWindowsMSVCEnvironment() &&
@@ -334,6 +358,7 @@ void Flang::addTargetOptions(const ArgList &Args,
334358

335359
if (Triple.isKnownWindowsMSVCEnvironment()) {
336360
processVSRuntimeLibrary(TC, Args, CmdArgs);
361+
addVSDefines(TC, Args, CmdArgs);
337362
}
338363

339364
// TODO: Add target specific flags, ABI, mtune option etc.

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4721,8 +4721,15 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
47214721
Left.isOneOf(TT_VerilogDimensionedTypeName, Keywords.kw_function)) {
47224722
return true;
47234723
}
4724+
// In a tagged union expression, there should be a space after the tag.
4725+
if (Right.isOneOf(tok::period, Keywords.kw_apostrophe) &&
4726+
Keywords.isVerilogIdentifier(Left) && Left.getPreviousNonComment() &&
4727+
Left.getPreviousNonComment()->is(Keywords.kw_tagged)) {
4728+
return true;
4729+
}
47244730
// Don't add spaces between a casting type and the quote or repetition count
4725-
// and the brace.
4731+
// and the brace. The case of tagged union expressions is handled by the
4732+
// previous rule.
47264733
if ((Right.is(Keywords.kw_apostrophe) ||
47274734
(Right.is(BK_BracedInit) && Right.is(tok::l_brace))) &&
47284735
!(Left.isOneOf(Keywords.kw_assign, Keywords.kw_unique) ||

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2528,7 +2528,8 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
25282528
skipUntilPragmaOpenMPEnd(DKind);
25292529
if (Tok.is(tok::annot_pragma_openmp_end))
25302530
ConsumeAnnotationToken();
2531-
break;
2531+
// return an empty statement
2532+
return StmtEmpty();
25322533
case OMPD_metadirective: {
25332534
ConsumeToken();
25342535
SmallVector<VariantMatchInfo, 4> VMIs;

0 commit comments

Comments
 (0)