Skip to content

Commit 417c0fa

Browse files
committed
Merge from 'main' to 'sycl-web' (24 commits)
CONFLICT (content): Merge conflict in clang/tools/clang-sycl-linker/CMakeLists.txt
2 parents a6733fd + 0d499f9 commit 417c0fa

File tree

101 files changed

+31351
-5431
lines changed

Some content is hidden

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

101 files changed

+31351
-5431
lines changed

clang/Maintainers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Sema
7272
Experimental new constant interpreter
7373
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7474
| Timm Bäder
75-
| tbaeder\@redhat.com (em), tbaeder (Phabricator), tbaederr (GitHub), tbaeder (Discourse), tbaeder (Discord)
75+
| tbaeder\@redhat.com (email), tbaeder (Phabricator), tbaederr (GitHub), tbaeder (Discourse), tbaeder (Discord)
7676
7777

7878
Modules & serialization

clang/docs/RealtimeSanitizer.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ projects. RTSan can be used to detect real-time violations, i.e. calls to method
1212
that are not safe for use in functions with deterministic run time requirements.
1313
RTSan considers any function marked with the ``[[clang::nonblocking]]`` attribute
1414
to be a real-time function. At run-time, if RTSan detects a call to ``malloc``,
15-
``free``, ``pthread_mutex_lock``, or anything else that could have a
15+
``free``, ``pthread_mutex_lock``, or anything else known to have a
1616
non-deterministic execution time in a function marked ``[[clang::nonblocking]]``
17-
RTSan raises an error.
17+
it raises an error.
1818

1919
RTSan performs its analysis at run-time but shares the ``[[clang::nonblocking]]``
2020
attribute with the :doc:`FunctionEffectAnalysis` system, which operates at

clang/lib/AST/ByteCode/Program.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,10 @@ Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty,
399399
}
400400

401401
// Arrays.
402-
if (const auto ArrayType = Ty->getAsArrayTypeUnsafe()) {
402+
if (const auto *ArrayType = Ty->getAsArrayTypeUnsafe()) {
403403
QualType ElemTy = ArrayType->getElementType();
404404
// Array of well-known bounds.
405-
if (auto CAT = dyn_cast<ConstantArrayType>(ArrayType)) {
405+
if (const auto *CAT = dyn_cast<ConstantArrayType>(ArrayType)) {
406406
size_t NumElems = CAT->getZExtSize();
407407
if (std::optional<PrimType> T = Ctx.classify(ElemTy)) {
408408
// Arrays of primitives.

clang/lib/Driver/ToolChains/PS4CPU.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
241241
// handled somewhere else.
242242
Args.ClaimAllArgs(options::OPT_w);
243243

244+
CmdArgs.push_back("-m");
245+
CmdArgs.push_back("elf_x86_64_fbsd");
246+
244247
CmdArgs.push_back(
245248
Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
246249

clang/test/Driver/ps5-linker.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
// Test that a target emulation is supplied to the linker
2+
3+
// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-EMU %s
4+
5+
// CHECK-EMU: {{ld(\.exe)?}}"
6+
// CHECK-EMU-SAME: "-m" "elf_x86_64_fbsd"
7+
18
// Test that PIE is the default for main components
29

310
// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-PIE %s

clang/tools/clang-sycl-linker/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
set(LLVM_LINK_COMPONENTS
22
${LLVM_TARGETS_TO_BUILD}
3+
<<<<<<< HEAD
34
Support
45
BinaryFormat
56
TargetParser
7+
=======
8+
BinaryFormat
9+
>>>>>>> 0d499f9043fed14ff8c7f9e24e19206c93aee5dd
610
Option
11+
Object
12+
TargetParser
13+
Support
714
)
815

916
set(LLVM_TARGET_DEFINITIONS SYCLLinkOpts.td)

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,19 @@ INTERCEPTOR(void *, valloc, SIZE_T size) {
467467
}
468468

469469
#if SANITIZER_INTERCEPT_ALIGNED_ALLOC
470+
471+
// In some cases, when targeting older Darwin versions, this warning may pop up.
472+
// Because we are providing a wrapper, the client is responsible to check
473+
// whether aligned_alloc is available, not us. We still succeed linking on an
474+
// old OS, because we are using a weak symbol (see aligned_alloc in
475+
// sanitizer_platform_interceptors.h)
476+
#pragma clang diagnostic push
477+
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
470478
INTERCEPTOR(void *, aligned_alloc, SIZE_T alignment, SIZE_T size) {
471479
__rtsan_notify_intercepted_call("aligned_alloc");
472480
return REAL(aligned_alloc)(alignment, size);
473481
}
482+
#pragma clang diagnostic pop
474483
#define RTSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC INTERCEPT_FUNCTION(aligned_alloc)
475484
#else
476485
#define RTSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC

compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,20 @@ TEST(TestRtsanInterceptors, VallocDiesWhenRealtime) {
122122
ExpectNonRealtimeSurvival(Func);
123123
}
124124

125-
#if SANITIZER_INTERCEPT_ALIGNED_ALLOC
125+
#if __has_builtin(__builtin_available) && SANITIZER_APPLE
126+
#define ALIGNED_ALLOC_AVAILABLE() (__builtin_available(macOS 10.15, *))
127+
#else
128+
// We are going to assume this is true until we hit systems where it isn't
129+
#define ALIGNED_ALLOC_AVAILABLE() (true)
130+
#endif
131+
126132
TEST(TestRtsanInterceptors, AlignedAllocDiesWhenRealtime) {
127-
auto Func = []() { EXPECT_NE(nullptr, aligned_alloc(16, 32)); };
128-
ExpectRealtimeDeath(Func, "aligned_alloc");
129-
ExpectNonRealtimeSurvival(Func);
133+
if (ALIGNED_ALLOC_AVAILABLE()) {
134+
auto Func = []() { EXPECT_NE(nullptr, aligned_alloc(16, 32)); };
135+
ExpectRealtimeDeath(Func, "aligned_alloc");
136+
ExpectNonRealtimeSurvival(Func);
137+
}
130138
}
131-
#endif
132139

133140
// free_sized and free_aligned_sized (both C23) are not yet supported
134141
TEST(TestRtsanInterceptors, FreeDiesWhenRealtime) {

compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,25 @@
8484
#define SI_NOT_MAC 1
8585
#endif
8686

87+
#if SANITIZER_APPLE
88+
# include <Availability.h>
89+
90+
// aligned_alloc was introduced in OSX 10.15
91+
// Linking will fail when using an older SDK
92+
# if defined(__MAC_10_15)
93+
// macOS 10.15 is greater than our minimal deployment target. To ensure we
94+
// generate a weak reference so the dylib continues to work on older
95+
// systems, we need to forward declare the intercepted function as "weak
96+
// imports".
97+
SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
98+
__sanitizer::usize __size);
99+
# define SI_MAC_SDK_10_15_AVAILABLE 1
100+
# else
101+
# define SI_MAC_SDK_10_15_AVAILABLE 0
102+
# endif // defined(__MAC_10_15)
103+
104+
#endif // SANITIZER_APPLE
105+
87106
#if SANITIZER_IOS
88107
#define SI_IOS 1
89108
#else
@@ -500,7 +519,8 @@
500519
#define SANITIZER_INTERCEPT_PVALLOC (SI_GLIBC || SI_ANDROID)
501520
#define SANITIZER_INTERCEPT_CFREE (SI_GLIBC && !SANITIZER_RISCV64)
502521
#define SANITIZER_INTERCEPT_REALLOCARRAY SI_POSIX
503-
#define SANITIZER_INTERCEPT_ALIGNED_ALLOC (!SI_MAC)
522+
#define SANITIZER_INTERCEPT_ALIGNED_ALLOC \
523+
(!SI_MAC || SI_MAC_SDK_10_15_AVAILABLE)
504524
#define SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE (!SI_MAC && !SI_NETBSD)
505525
#define SANITIZER_INTERCEPT_MCHECK_MPROBE SI_LINUX_NOT_ANDROID
506526
#define SANITIZER_INTERCEPT_WCSLEN 1

flang/lib/Optimizer/Transforms/CUFAddConstructor.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
#include "flang/Optimizer/Builder/Runtime/RTBuilder.h"
1212
#include "flang/Optimizer/Builder/Todo.h"
1313
#include "flang/Optimizer/CodeGen/Target.h"
14+
#include "flang/Optimizer/CodeGen/TypeConverter.h"
1415
#include "flang/Optimizer/Dialect/CUF/CUFOps.h"
1516
#include "flang/Optimizer/Dialect/FIRAttr.h"
1617
#include "flang/Optimizer/Dialect/FIRDialect.h"
1718
#include "flang/Optimizer/Dialect/FIROps.h"
1819
#include "flang/Optimizer/Dialect/FIROpsSupport.h"
20+
#include "flang/Optimizer/Dialect/FIRType.h"
1921
#include "flang/Optimizer/Support/DataLayout.h"
2022
#include "flang/Optimizer/Transforms/CUFCommon.h"
2123
#include "flang/Runtime/CUDA/registration.h"
@@ -84,6 +86,8 @@ struct CUFAddConstructor
8486
auto registeredMod = builder.create<cuf::RegisterModuleOp>(
8587
loc, llvmPtrTy, mlir::SymbolRefAttr::get(ctx, gpuMod.getName()));
8688

89+
fir::LLVMTypeConverter typeConverter(mod, /*applyTBAA=*/false,
90+
/*forceUnifiedTBAATree=*/false, *dl);
8791
// Register kernels
8892
for (auto func : gpuMod.getOps<mlir::gpu::GPUFuncOp>()) {
8993
if (func.isKernel()) {
@@ -115,17 +119,25 @@ struct CUFAddConstructor
115119
fir::factory::createStringLiteral(builder, loc, gblNameStr));
116120

117121
// Global variable size
118-
auto sizeAndAlign = fir::getTypeSizeAndAlignmentOrCrash(
119-
loc, globalOp.getType(), *dl, kindMap);
120-
auto size =
121-
builder.createIntegerConstant(loc, idxTy, sizeAndAlign.first);
122+
std::optional<uint64_t> size;
123+
if (auto boxTy =
124+
mlir::dyn_cast<fir::BaseBoxType>(globalOp.getType())) {
125+
mlir::Type structTy = typeConverter.convertBoxTypeAsStruct(boxTy);
126+
size = dl->getTypeSizeInBits(structTy) / 8;
127+
}
128+
if (!size) {
129+
size = fir::getTypeSizeAndAlignmentOrCrash(loc, globalOp.getType(),
130+
*dl, kindMap)
131+
.first;
132+
}
133+
auto sizeVal = builder.createIntegerConstant(loc, idxTy, *size);
122134

123135
// Global variable address
124136
mlir::Value addr = builder.create<fir::AddrOfOp>(
125137
loc, globalOp.resultType(), globalOp.getSymbol());
126138

127139
llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments(
128-
builder, loc, fTy, registeredMod, addr, gblName, size)};
140+
builder, loc, fTy, registeredMod, addr, gblName, sizeVal)};
129141
builder.create<fir::CallOp>(loc, func, args);
130142
} break;
131143
case cuf::DataAttribute::Managed:

0 commit comments

Comments
 (0)