Skip to content

Commit ed0ac30

Browse files
committed
merge main into amd-staging
2 parents e5a81a6 + a3aa452 commit ed0ac30

File tree

52 files changed

+1089
-334
lines changed

Some content is hidden

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

52 files changed

+1089
-334
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ C++ Language Changes
6060

6161
C++2c Feature Support
6262
^^^^^^^^^^^^^^^^^^^^^
63-
- Compiler flags ``-std=c++2c`` and ``-std=gnu++2c`` have been added for experimental C++2c implementation work.
64-
- Implemented `P2738R1: constexpr cast from void* <https://wg21.link/P2738R1>`_.
65-
- Partially implemented `P2361R6: constexpr cast from void* <https://wg21.link/P2361R6>`_.
66-
The changes to attributes declarations are not part of this release.
67-
- Implemented `P2741R3: user-generated static_assert messages <https://wg21.link/P2741R3>`_.
6863

6964
C++23 Feature Support
7065
^^^^^^^^^^^^^^^^^^^^^

clang/unittests/Format/ConfigParseTest.cpp

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ TEST(ConfigParseTest, GetsCorrectBasedOnStyle) {
144144
EXPECT_EQ(0, parseConfiguration(TEXT, &Style).value()); \
145145
EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
146146

147+
#define CHECK_PARSE_INT(FIELD) CHECK_PARSE(#FIELD ": -1234", FIELD, -1234)
148+
149+
#define CHECK_PARSE_UNSIGNED(FIELD) CHECK_PARSE(#FIELD ": 1234", FIELD, 1234u)
150+
147151
#define CHECK_PARSE_LIST(FIELD) \
148152
CHECK_PARSE(#FIELD ": [foo]", FIELD, std::vector<std::string>{"foo"})
149153

@@ -254,35 +258,40 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
254258

255259
#undef CHECK_PARSE_BOOL
256260

261+
TEST(ConfigParseTest, ParsesConfigurationIntegers) {
262+
FormatStyle Style = {};
263+
Style.Language = FormatStyle::LK_Cpp;
264+
265+
CHECK_PARSE_INT(AccessModifierOffset);
266+
CHECK_PARSE_INT(PPIndentWidth);
267+
268+
CHECK_PARSE_UNSIGNED(BracedInitializerIndentWidth);
269+
CHECK_PARSE_UNSIGNED(ColumnLimit);
270+
CHECK_PARSE_UNSIGNED(ConstructorInitializerIndentWidth);
271+
CHECK_PARSE_UNSIGNED(ContinuationIndentWidth);
272+
CHECK_PARSE_UNSIGNED(IndentWidth);
273+
CHECK_PARSE_UNSIGNED(MaxEmptyLinesToKeep);
274+
CHECK_PARSE_UNSIGNED(ObjCBlockIndentWidth);
275+
CHECK_PARSE_UNSIGNED(PenaltyBreakAssignment);
276+
CHECK_PARSE_UNSIGNED(PenaltyBreakBeforeFirstCallParameter);
277+
CHECK_PARSE_UNSIGNED(PenaltyBreakBeforeMemberAccess);
278+
CHECK_PARSE_UNSIGNED(PenaltyBreakComment);
279+
CHECK_PARSE_UNSIGNED(PenaltyBreakFirstLessLess);
280+
CHECK_PARSE_UNSIGNED(PenaltyBreakOpenParenthesis);
281+
CHECK_PARSE_UNSIGNED(PenaltyBreakScopeResolution);
282+
CHECK_PARSE_UNSIGNED(PenaltyBreakString);
283+
CHECK_PARSE_UNSIGNED(PenaltyBreakTemplateDeclaration);
284+
CHECK_PARSE_UNSIGNED(PenaltyExcessCharacter);
285+
CHECK_PARSE_UNSIGNED(PenaltyIndentedWhitespace);
286+
CHECK_PARSE_UNSIGNED(PenaltyReturnTypeOnItsOwnLine);
287+
CHECK_PARSE_UNSIGNED(ShortNamespaceLines);
288+
CHECK_PARSE_UNSIGNED(SpacesBeforeTrailingComments);
289+
CHECK_PARSE_UNSIGNED(TabWidth);
290+
}
291+
257292
TEST(ConfigParseTest, ParsesConfiguration) {
258293
FormatStyle Style = {};
259294
Style.Language = FormatStyle::LK_Cpp;
260-
CHECK_PARSE("AccessModifierOffset: -1234", AccessModifierOffset, -1234);
261-
CHECK_PARSE("ConstructorInitializerIndentWidth: 1234",
262-
ConstructorInitializerIndentWidth, 1234u);
263-
CHECK_PARSE("ObjCBlockIndentWidth: 1234", ObjCBlockIndentWidth, 1234u);
264-
CHECK_PARSE("ColumnLimit: 1234", ColumnLimit, 1234u);
265-
CHECK_PARSE("MaxEmptyLinesToKeep: 1234", MaxEmptyLinesToKeep, 1234u);
266-
CHECK_PARSE("PenaltyBreakAssignment: 1234", PenaltyBreakAssignment, 1234u);
267-
CHECK_PARSE("PenaltyBreakBeforeFirstCallParameter: 1234",
268-
PenaltyBreakBeforeFirstCallParameter, 1234u);
269-
CHECK_PARSE("PenaltyBreakBeforeMemberAccess: 1234",
270-
PenaltyBreakBeforeMemberAccess, 1234u);
271-
CHECK_PARSE("PenaltyBreakTemplateDeclaration: 1234",
272-
PenaltyBreakTemplateDeclaration, 1234u);
273-
CHECK_PARSE("PenaltyBreakOpenParenthesis: 1234", PenaltyBreakOpenParenthesis,
274-
1234u);
275-
CHECK_PARSE("PenaltyBreakScopeResolution: 1234", PenaltyBreakScopeResolution,
276-
1234u);
277-
CHECK_PARSE("PenaltyExcessCharacter: 1234", PenaltyExcessCharacter, 1234u);
278-
CHECK_PARSE("PenaltyReturnTypeOnItsOwnLine: 1234",
279-
PenaltyReturnTypeOnItsOwnLine, 1234u);
280-
CHECK_PARSE("SpacesBeforeTrailingComments: 1234",
281-
SpacesBeforeTrailingComments, 1234u);
282-
CHECK_PARSE("IndentWidth: 32", IndentWidth, 32u);
283-
CHECK_PARSE("ContinuationIndentWidth: 11", ContinuationIndentWidth, 11u);
284-
CHECK_PARSE("BracedInitializerIndentWidth: 34", BracedInitializerIndentWidth,
285-
34);
286295
CHECK_PARSE("CommentPragmas: '// abc$'", CommentPragmas, "// abc$");
287296

288297
Style.QualifierAlignment = FormatStyle::QAS_Right;

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void OSSpinLockLock(volatile OSSpinLock *__lock);
4747
#include <stdarg.h>
4848
#include <stdio.h>
4949
#if SANITIZER_LINUX
50+
#include <linux/mman.h>
5051
#include <sys/inotify.h>
5152
#endif
5253
#include <sys/select.h>
@@ -870,6 +871,32 @@ INTERCEPTOR(void *, mmap64, void *addr, size_t length, int prot, int flags,
870871
#define RTSAN_MAYBE_INTERCEPT_MMAP64
871872
#endif // SANITIZER_INTERCEPT_MMAP64
872873

874+
#if SANITIZER_LINUX
875+
// Note that even if rtsan is ported to netbsd, it has a slighty different
876+
// and non-variadic signature
877+
INTERCEPTOR(void *, mremap, void *oaddr, size_t olength, size_t nlength,
878+
int flags, ...) {
879+
__rtsan_notify_intercepted_call("mremap");
880+
881+
// the last optional argument is only used in this case
882+
// as the new page region will be assigned to. Is ignored otherwise.
883+
if (flags & MREMAP_FIXED) {
884+
va_list args;
885+
886+
va_start(args, flags);
887+
void *naddr = va_arg(args, void *);
888+
va_end(args);
889+
890+
return REAL(mremap)(oaddr, olength, nlength, flags, naddr);
891+
}
892+
893+
return REAL(mremap)(oaddr, olength, nlength, flags);
894+
}
895+
#define RTSAN_MAYBE_INTERCEPT_MREMAP INTERCEPT_FUNCTION(mremap)
896+
#else
897+
#define RTSAN_MAYBE_INTERCEPT_MREMAP
898+
#endif
899+
873900
INTERCEPTOR(int, munmap, void *addr, size_t length) {
874901
__rtsan_notify_intercepted_call("munmap");
875902
return REAL(munmap)(addr, length);
@@ -1346,6 +1373,7 @@ void __rtsan::InitializeInterceptors() {
13461373
INTERCEPT_FUNCTION(posix_memalign);
13471374
INTERCEPT_FUNCTION(mmap);
13481375
RTSAN_MAYBE_INTERCEPT_MMAP64;
1376+
RTSAN_MAYBE_INTERCEPT_MREMAP;
13491377
INTERCEPT_FUNCTION(munmap);
13501378
RTSAN_MAYBE_INTERCEPT_MADVISE;
13511379
RTSAN_MAYBE_INTERCEPT_POSIX_MADVISE;

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,16 @@ TEST(TestRtsanInterceptors, MmapDiesWhenRealtime) {
197197
ExpectNonRealtimeSurvival(Func);
198198
}
199199

200+
#if SANITIZER_LINUX
201+
TEST(TestRtsanInterceptors, MremapDiesWhenRealtime) {
202+
void *addr = mmap(nullptr, 8, PROT_READ | PROT_WRITE,
203+
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
204+
auto Func = [addr]() { void *_ = mremap(addr, 8, 16, 0); };
205+
ExpectRealtimeDeath(Func, "mremap");
206+
ExpectNonRealtimeSurvival(Func);
207+
}
208+
#endif
209+
200210
TEST(TestRtsanInterceptors, MunmapDiesWhenRealtime) {
201211
void *ptr = mmap(nullptr, 8, PROT_READ | PROT_WRITE,
202212
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);

flang/CMakeLists.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,13 @@ if (FLANG_INCLUDE_TESTS)
471471
add_compile_definitions(FLANG_INCLUDE_TESTS=1)
472472
endif()
473473

474+
option(FLANG_CUF_RUNTIME
475+
"Compile CUDA Fortran runtime sources" OFF)
476+
if (FLANG_CUF_RUNTIME)
477+
find_package(CUDAToolkit REQUIRED)
478+
add_compile_definitions(FLANG_CUDA_SUPPORT=1)
479+
endif()
480+
474481
add_subdirectory(include)
475482
add_subdirectory(lib)
476483
add_subdirectory(cmake/modules)
@@ -481,12 +488,6 @@ if (FLANG_BUILD_TOOLS)
481488
add_subdirectory(tools)
482489
endif()
483490

484-
option(FLANG_CUF_RUNTIME
485-
"Compile CUDA Fortran runtime sources" OFF)
486-
if (FLANG_CUF_RUNTIME)
487-
find_package(CUDAToolkit REQUIRED)
488-
endif()
489-
490491
add_subdirectory(runtime)
491492

492493
if (LLVM_INCLUDE_EXAMPLES)

flang/include/flang/Optimizer/Builder/Runtime/Main.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class GlobalOp;
2424
namespace fir::runtime {
2525

2626
void genMain(fir::FirOpBuilder &builder, mlir::Location loc,
27-
const std::vector<Fortran::lower::EnvironmentDefault> &defs);
27+
const std::vector<Fortran::lower::EnvironmentDefault> &defs,
28+
bool initCuda = false);
2829
}
2930

3031
#endif // FORTRAN_OPTIMIZER_BUILDER_RUNTIME_MAIN_H
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- include/flang/Runtime/CUDA/init.h -----------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef FORTRAN_RUNTIME_CUDA_INIT_H_
10+
#define FORTRAN_RUNTIME_CUDA_INIT_H_
11+
12+
#include "common.h"
13+
#include "flang/Runtime/entry-names.h"
14+
15+
extern "C" {
16+
17+
void RTDECL(CUFInit)();
18+
}
19+
20+
#endif // FORTRAN_RUNTIME_CUDA_INIT_H_

flang/lib/Lower/Bridge.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,9 @@ class FirConverter : public Fortran::lower::AbstractConverter {
459459
if (hasMainProgram)
460460
createGlobalOutsideOfFunctionLowering([&]() {
461461
fir::runtime::genMain(*builder, toLocation(),
462-
bridge.getEnvironmentDefaults());
462+
bridge.getEnvironmentDefaults(),
463+
getFoldingContext().languageFeatures().IsEnabled(
464+
Fortran::common::LanguageFeature::CUDA));
463465
});
464466

465467
finalizeOpenACCLowering();

flang/lib/Optimizer/Builder/Runtime/Main.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@
1616
#include "flang/Optimizer/Dialect/FIRType.h"
1717
#include "flang/Runtime/main.h"
1818
#include "flang/Runtime/stop.h"
19+
#ifdef FLANG_CUDA_SUPPORT
20+
#include "flang/Runtime/CUDA/init.h"
21+
#endif
1922

2023
using namespace Fortran::runtime;
2124

2225
/// Create a `int main(...)` that calls the Fortran entry point
2326
void fir::runtime::genMain(
2427
fir::FirOpBuilder &builder, mlir::Location loc,
25-
const std::vector<Fortran::lower::EnvironmentDefault> &defs) {
28+
const std::vector<Fortran::lower::EnvironmentDefault> &defs,
29+
bool initCuda) {
2630
auto *context = builder.getContext();
2731
auto argcTy = builder.getDefaultIntegerType();
2832
auto ptrTy = mlir::LLVM::LLVMPointerType::get(context);
@@ -61,6 +65,15 @@ void fir::runtime::genMain(
6165
args.push_back(env);
6266

6367
builder.create<fir::CallOp>(loc, startFn, args);
68+
69+
#ifdef FLANG_CUDA_SUPPORT
70+
if (initCuda) {
71+
auto initFn = builder.createFunction(
72+
loc, RTNAME_STRING(CUFInit), mlir::FunctionType::get(context, {}, {}));
73+
builder.create<fir::CallOp>(loc, initFn);
74+
}
75+
#endif
76+
6477
builder.create<fir::CallOp>(loc, qqMainFn);
6578
builder.create<fir::CallOp>(loc, stopFn);
6679

flang/runtime/CUDA/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_flang_library(${CUFRT_LIBNAME}
1717
allocator.cpp
1818
allocatable.cpp
1919
descriptor.cpp
20+
init.cpp
2021
kernel.cpp
2122
memmove-function.cpp
2223
memory.cpp

0 commit comments

Comments
 (0)