Skip to content

Commit 4f4c49d

Browse files
committed
Merge from 'main' to 'sycl-web' (28 commits)
CONFLICT (content): Merge conflict in llvm/unittests/Support/CMakeLists.txt
2 parents 9722eb8 + 07deaf8 commit 4f4c49d

File tree

170 files changed

+6984
-689
lines changed

Some content is hidden

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

170 files changed

+6984
-689
lines changed

.github/workflows/libc-fullbuild-tests.yml

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,23 @@ jobs:
1919
include:
2020
- os: ubuntu-24.04
2121
ccache-variant: sccache
22-
c_compiler: clang-20
23-
cpp_compiler: clang++-20
22+
c_compiler: clang-21
23+
cpp_compiler: clang++-21
24+
target: x86_64-unknown-linux-llvm
25+
include_scudo: ON
2426
# TODO: remove ccache logic when https://github.com/hendrikmuhs/ccache-action/issues/279 is resolved.
2527
- os: ubuntu-24.04-arm
2628
ccache-variant: ccache
27-
c_compiler: clang-20
28-
cpp_compiler: clang++-20
29+
c_compiler: clang-21
30+
cpp_compiler: clang++-21
31+
target: aarch64-unknown-linux-llvm
32+
include_scudo: ON
33+
- os: ubuntu-24.04
34+
ccache-variant: ccache
35+
c_compiler: clang-21
36+
cpp_compiler: clang++-21
37+
target: x86_64-unknown-uefi-llvm
38+
include_scudo: OFF
2939
# TODO: add back gcc build when it is fixed
3040
# - c_compiler: gcc
3141
# cpp_compiler: g++
@@ -53,7 +63,7 @@ jobs:
5363
run: |
5464
wget https://apt.llvm.org/llvm.sh
5565
chmod +x llvm.sh
56-
sudo ./llvm.sh 20
66+
sudo ./llvm.sh 21
5767
sudo apt-get update
5868
sudo apt-get install -y libmpfr-dev libgmp-dev libmpc-dev ninja-build linux-libc-dev
5969
sudo ln -sf /usr/include/$(uname -p)-linux-gnu/asm /usr/include/asm
@@ -68,22 +78,31 @@ jobs:
6878
# Configure libc fullbuild with scudo.
6979
# Use MinSizeRel to reduce the size of the build.
7080
- name: Configure CMake
71-
run: >
72-
cmake -B ${{ steps.strings.outputs.build-output-dir }}
73-
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
74-
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
75-
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
76-
-DCMAKE_C_COMPILER_LAUNCHER=${{ matrix.ccache-variant }}
77-
-DCMAKE_CXX_COMPILER_LAUNCHER=${{ matrix.ccache-variant }}
78-
-DCMAKE_INSTALL_PREFIX=${{ steps.strings.outputs.build-install-dir }}
79-
-DLLVM_ENABLE_RUNTIMES="libc;compiler-rt"
80-
-DLLVM_LIBC_FULL_BUILD=ON
81-
-DLLVM_LIBC_INCLUDE_SCUDO=ON
82-
-DCOMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC=ON
83-
-DCOMPILER_RT_BUILD_GWP_ASAN=OFF
84-
-DCOMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED=OFF
85-
-G Ninja
86-
-S ${{ github.workspace }}/runtimes
81+
run: |
82+
export RUNTIMES="libc"
83+
84+
if [[ ${{ matrix.include_scudo}} == "ON" ]]; then
85+
export RUNTIMES="$RUNTIMES;compiler-rt"
86+
export CMAKE_FLAGS="
87+
-DLLVM_LIBC_INCLUDE_SCUDO=ON
88+
-DCOMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC=ON
89+
-DCOMPILER_RT_BUILD_GWP_ASAN=OFF
90+
-DCOMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED=OFF"
91+
fi
92+
93+
cmake -B ${{ steps.strings.outputs.build-output-dir }} \
94+
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} \
95+
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }} \
96+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
97+
-DCMAKE_C_COMPILER_LAUNCHER=${{ matrix.ccache-variant }} \
98+
-DCMAKE_CXX_COMPILER_LAUNCHER=${{ matrix.ccache-variant }} \
99+
-DCMAKE_INSTALL_PREFIX=${{ steps.strings.outputs.build-install-dir }} \
100+
-DLLVM_RUNTIMES_TARGET=${{ matrix.target }} \
101+
-DLLVM_ENABLE_RUNTIMES="$RUNTIMES" \
102+
-DLLVM_LIBC_FULL_BUILD=ON \
103+
-G Ninja \
104+
-S ${{ github.workspace }}/runtimes \
105+
$CMAKE_FLAGS
87106
88107
- name: Build
89108
run: >
@@ -93,6 +112,8 @@ jobs:
93112
--target install
94113
95114
- name: Test
115+
# Skip UEFI tests until we have testing set up.
116+
if: ${{ ! endsWith(matrix.target, '-uefi-llvm') }}
96117
run: >
97118
cmake
98119
--build ${{ steps.strings.outputs.build-output-dir }}

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ Non-comprehensive list of changes in this release
251251
- Added `__builtin_elementwise_minnum` and `__builtin_elementwise_maxnum`.
252252
- No longer crashing on invalid Objective-C categories and extensions when
253253
dumping the AST as JSON. (#GH137320)
254+
- Clang itself now uses split stacks instead of threads for allocating more
255+
stack space when running on Apple AArch64 based platforms. This means that
256+
stack traces of Clang from debuggers, crashes, and profilers may look
257+
different than before.
254258

255259
New Compiler Flags
256260
------------------

clang/include/clang/Basic/Stack.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ namespace clang {
2727

2828
/// Call this once on each thread, as soon after starting the thread as
2929
/// feasible, to note the approximate address of the bottom of the stack.
30-
void noteBottomOfStack();
30+
///
31+
/// \param ForceSet set to true if you know the call is near the bottom of a
32+
/// new stack. Used for split stacks.
33+
void noteBottomOfStack(bool ForceSet = false);
3134

3235
/// Determine whether the stack is nearly exhausted.
3336
bool isStackNearlyExhausted();

clang/include/clang/CIR/Dialect/IR/CIRTypes.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ def CIR_RecordType : CIR_Type<"Record", "record",
531531
bool isComplete() const { return !isIncomplete(); };
532532
bool isIncomplete() const;
533533

534+
mlir::Type getLargestMember(const mlir::DataLayout &dataLayout) const;
534535
size_t getNumElements() const { return getMembers().size(); };
535536
std::string getKindAsStr() {
536537
switch (getKind()) {

clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,25 @@ struct ModuleDeps {
178178
/// on, not including transitive dependencies.
179179
std::vector<PrebuiltModuleDep> PrebuiltModuleDeps;
180180

181-
/// A list of module identifiers this module directly depends on, not
182-
/// including transitive dependencies.
181+
/// This struct contains information about a single dependency.
182+
struct DepInfo {
183+
/// Identifies the dependency.
184+
ModuleID ID;
185+
186+
/// Indicates if the module that has this dependency exports it or not.
187+
bool Exported = false;
188+
189+
bool operator<(const DepInfo &Other) const {
190+
return std::tie(ID, Exported) < std::tie(Other.ID, Other.Exported);
191+
}
192+
};
193+
194+
/// A list of DepsInfo containing information about modules this module
195+
/// directly depends on, not including transitive dependencies.
183196
///
184197
/// This may include modules with a different context hash when it can be
185198
/// determined that the differences are benign for this compilation.
186-
std::vector<ModuleID> ClangModuleDeps;
199+
std::vector<ModuleDeps::DepInfo> ClangModuleDeps;
187200

188201
/// The set of libraries or frameworks to link against when
189202
/// an entity from this module is used.
@@ -270,7 +283,8 @@ class ModuleDepCollectorPP final : public PPCallbacks {
270283
llvm::DenseSet<const Module *> &AddedModules);
271284

272285
/// Add discovered module dependency for the given module.
273-
void addOneModuleDep(const Module *M, const ModuleID ID, ModuleDeps &MD);
286+
void addOneModuleDep(const Module *M, bool Exported, const ModuleID ID,
287+
ModuleDeps &MD);
274288
};
275289

276290
/// Collects modular and non-modular dependencies of the main file by attaching
@@ -352,16 +366,16 @@ class ModuleDepCollector final : public DependencyCollector {
352366

353367
/// Collect module map files for given modules.
354368
llvm::DenseSet<const FileEntry *>
355-
collectModuleMapFiles(ArrayRef<ModuleID> ClangModuleDeps) const;
369+
collectModuleMapFiles(ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const;
356370

357371
/// Add module map files to the invocation, if needed.
358372
void addModuleMapFiles(CompilerInvocation &CI,
359-
ArrayRef<ModuleID> ClangModuleDeps) const;
373+
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const;
360374
/// Add module files (pcm) to the invocation, if needed.
361375
void addModuleFiles(CompilerInvocation &CI,
362-
ArrayRef<ModuleID> ClangModuleDeps) const;
376+
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const;
363377
void addModuleFiles(CowCompilerInvocation &CI,
364-
ArrayRef<ModuleID> ClangModuleDeps) const;
378+
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const;
365379

366380
/// Add paths that require looking up outputs to the given dependencies.
367381
void addOutputPaths(CowCompilerInvocation &CI, ModuleDeps &Deps);

clang/lib/Basic/Stack.cpp

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,13 @@
1313

1414
#include "clang/Basic/Stack.h"
1515
#include "llvm/Support/CrashRecoveryContext.h"
16+
#include "llvm/Support/ProgramStack.h"
1617

17-
#ifdef _MSC_VER
18-
#include <intrin.h> // for _AddressOfReturnAddress
19-
#endif
18+
static LLVM_THREAD_LOCAL uintptr_t BottomOfStack = 0;
2019

21-
static LLVM_THREAD_LOCAL void *BottomOfStack = nullptr;
22-
23-
static void *getStackPointer() {
24-
#if __GNUC__ || __has_builtin(__builtin_frame_address)
25-
return __builtin_frame_address(0);
26-
#elif defined(_MSC_VER)
27-
return _AddressOfReturnAddress();
28-
#else
29-
char CharOnStack = 0;
30-
// The volatile store here is intended to escape the local variable, to
31-
// prevent the compiler from optimizing CharOnStack into anything other
32-
// than a char on the stack.
33-
//
34-
// Tested on: MSVC 2015 - 2019, GCC 4.9 - 9, Clang 3.2 - 9, ICC 13 - 19.
35-
char *volatile Ptr = &CharOnStack;
36-
return Ptr;
37-
#endif
38-
}
39-
40-
void clang::noteBottomOfStack() {
41-
if (!BottomOfStack)
42-
BottomOfStack = getStackPointer();
20+
void clang::noteBottomOfStack(bool ForceSet) {
21+
if (!BottomOfStack || ForceSet)
22+
BottomOfStack = llvm::getStackPointer();
4323
}
4424

4525
bool clang::isStackNearlyExhausted() {
@@ -51,7 +31,8 @@ bool clang::isStackNearlyExhausted() {
5131
if (!BottomOfStack)
5232
return false;
5333

54-
intptr_t StackDiff = (intptr_t)getStackPointer() - (intptr_t)BottomOfStack;
34+
intptr_t StackDiff =
35+
(intptr_t)llvm::getStackPointer() - (intptr_t)BottomOfStack;
5536
size_t StackUsage = (size_t)std::abs(StackDiff);
5637

5738
// If the stack pointer has a surprising value, we do not understand this
@@ -66,9 +47,12 @@ bool clang::isStackNearlyExhausted() {
6647
void clang::runWithSufficientStackSpaceSlow(llvm::function_ref<void()> Diag,
6748
llvm::function_ref<void()> Fn) {
6849
llvm::CrashRecoveryContext CRC;
69-
CRC.RunSafelyOnThread([&] {
70-
noteBottomOfStack();
50+
// Preserve the BottomOfStack in case RunSafelyOnNewStack uses split stacks.
51+
uintptr_t PrevBottom = BottomOfStack;
52+
CRC.RunSafelyOnNewStack([&] {
53+
noteBottomOfStack(true);
7154
Diag();
7255
Fn();
7356
}, DesiredStackSize);
57+
BottomOfStack = PrevBottom;
7458
}

clang/lib/CIR/CodeGen/CIRGenDecl.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,13 @@ void CIRGenFunction::emitAutoVarInit(
9090
// If this local has an initializer, emit it now.
9191
const Expr *init = d.getInit();
9292

93-
if (!type.isPODType(getContext())) {
94-
cgm.errorNYI(d.getSourceRange(), "emitAutoVarInit: non-POD type");
93+
// Initialize the variable here if it doesn't have a initializer and it is a
94+
// C struct that is non-trivial to initialize or an array containing such a
95+
// struct.
96+
if (!init && type.isNonTrivialToPrimitiveDefaultInitialize() ==
97+
QualType::PDIK_Struct) {
98+
cgm.errorNYI(d.getSourceRange(),
99+
"emitAutoVarInit: non-trivial to default initialize");
95100
return;
96101
}
97102

@@ -240,7 +245,10 @@ void CIRGenFunction::emitExprAsInit(const Expr *init, const ValueDecl *d,
240245
QualType type = d->getType();
241246

242247
if (type->isReferenceType()) {
243-
cgm.errorNYI(init->getSourceRange(), "emitExprAsInit: reference type");
248+
RValue rvalue = emitReferenceBindingToExpr(init);
249+
if (capturedByInit)
250+
cgm.errorNYI(init->getSourceRange(), "emitExprAsInit: captured by init");
251+
emitStoreThroughLValue(rvalue, lvalue);
244252
return;
245253
}
246254
switch (CIRGenFunction::getEvaluationKind(type)) {

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -317,20 +317,21 @@ LValue CIRGenFunction::emitLValueForField(LValue base, const FieldDecl *field) {
317317
}
318318

319319
unsigned recordCVR = base.getVRQualifiers();
320-
if (rec->isUnion()) {
321-
cgm.errorNYI(field->getSourceRange(), "emitLValueForField: union");
322-
return LValue();
323-
}
324320

325-
assert(!cir::MissingFeatures::preservedAccessIndexRegion());
326321
llvm::StringRef fieldName = field->getName();
327-
const CIRGenRecordLayout &layout =
328-
cgm.getTypes().getCIRGenRecordLayout(field->getParent());
329-
unsigned fieldIndex = layout.getCIRFieldNo(field);
330-
322+
unsigned fieldIndex;
331323
assert(!cir::MissingFeatures::lambdaFieldToName());
332324

325+
if (rec->isUnion())
326+
fieldIndex = field->getFieldIndex();
327+
else {
328+
const CIRGenRecordLayout &layout =
329+
cgm.getTypes().getCIRGenRecordLayout(field->getParent());
330+
fieldIndex = layout.getCIRFieldNo(field);
331+
}
332+
333333
addr = emitAddrOfFieldStorage(addr, field, fieldName, fieldIndex);
334+
assert(!cir::MissingFeatures::preservedAccessIndexRegion());
334335

335336
// If this is a reference field, load the reference right now.
336337
if (fieldType->isReferenceType()) {
@@ -439,7 +440,13 @@ LValue CIRGenFunction::emitDeclRefLValue(const DeclRefExpr *e) {
439440
cgm.errorNYI(e->getSourceRange(), "emitDeclRefLValue: static local");
440441
}
441442

442-
return makeAddrLValue(addr, ty, AlignmentSource::Type);
443+
// Drill into reference types.
444+
LValue lv =
445+
vd->getType()->isReferenceType()
446+
? emitLoadOfReferenceLValue(addr, getLoc(e->getSourceRange()),
447+
vd->getType(), AlignmentSource::Decl)
448+
: makeAddrLValue(addr, ty, AlignmentSource::Decl);
449+
return lv;
443450
}
444451

445452
cgm.errorNYI(e->getSourceRange(), "emitDeclRefLValue: unhandled decl type");
@@ -1065,6 +1072,45 @@ mlir::Value CIRGenFunction::emitAlloca(StringRef name, mlir::Type ty,
10651072
return addr;
10661073
}
10671074

1075+
RValue CIRGenFunction::emitReferenceBindingToExpr(const Expr *e) {
1076+
// Emit the expression as an lvalue.
1077+
LValue lv = emitLValue(e);
1078+
assert(lv.isSimple());
1079+
mlir::Value value = lv.getPointer();
1080+
1081+
assert(!cir::MissingFeatures::sanitizers());
1082+
1083+
return RValue::get(value);
1084+
}
1085+
1086+
Address CIRGenFunction::emitLoadOfReference(LValue refLVal, mlir::Location loc,
1087+
LValueBaseInfo *pointeeBaseInfo) {
1088+
if (refLVal.isVolatile())
1089+
cgm.errorNYI(loc, "load of volatile reference");
1090+
1091+
cir::LoadOp load =
1092+
builder.create<cir::LoadOp>(loc, refLVal.getAddress().getElementType(),
1093+
refLVal.getAddress().getPointer());
1094+
1095+
assert(!cir::MissingFeatures::opTBAA());
1096+
1097+
QualType pointeeType = refLVal.getType()->getPointeeType();
1098+
CharUnits align = cgm.getNaturalTypeAlignment(pointeeType, pointeeBaseInfo);
1099+
return Address(load, convertTypeForMem(pointeeType), align);
1100+
}
1101+
1102+
LValue CIRGenFunction::emitLoadOfReferenceLValue(Address refAddr,
1103+
mlir::Location loc,
1104+
QualType refTy,
1105+
AlignmentSource source) {
1106+
LValue refLVal = makeAddrLValue(refAddr, refTy, LValueBaseInfo(source));
1107+
LValueBaseInfo pointeeBaseInfo;
1108+
assert(!cir::MissingFeatures::opTBAA());
1109+
Address pointeeAddr = emitLoadOfReference(refLVal, loc, &pointeeBaseInfo);
1110+
return makeAddrLValue(pointeeAddr, refLVal.getType()->getPointeeType(),
1111+
pointeeBaseInfo);
1112+
}
1113+
10681114
mlir::Value CIRGenFunction::createDummyValue(mlir::Location loc,
10691115
clang::QualType qt) {
10701116
mlir::Type t = convertType(qt);

clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- CIRGenExprAgg.cpp - Emit CIR Code from Aggregate Expressions -----===//
1+
//===- CIRGenExprAggregrate.cpp - Emit CIR Code from Aggregate Expressions ===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,11 @@ class CIRGenFunction : public CIRGenTypeCache {
560560
/// returning the rvalue.
561561
RValue emitLoadOfLValue(LValue lv, SourceLocation loc);
562562

563+
Address emitLoadOfReference(LValue refLVal, mlir::Location loc,
564+
LValueBaseInfo *pointeeBaseInfo);
565+
LValue emitLoadOfReferenceLValue(Address refAddr, mlir::Location loc,
566+
QualType refTy, AlignmentSource source);
567+
563568
/// EmitLoadOfScalar - Load a scalar value from an address, taking
564569
/// care to appropriately convert from the memory representation to
565570
/// the LLVM value representation. The l-value must be a simple
@@ -587,6 +592,9 @@ class CIRGenFunction : public CIRGenTypeCache {
587592
Address emitPointerWithAlignment(const clang::Expr *expr,
588593
LValueBaseInfo *baseInfo);
589594

595+
/// Emits a reference binding to the passed in expression.
596+
RValue emitReferenceBindingToExpr(const Expr *e);
597+
590598
mlir::LogicalResult emitReturnStmt(const clang::ReturnStmt &s);
591599

592600
/// Emit a conversion from the specified type to the specified destination

0 commit comments

Comments
 (0)