Skip to content

Commit 2f2ce7e

Browse files
author
Jenkins
committed
merge main into amd-staging
Change-Id: Ie599504ba4c5ea709b625b7ec025dbec244ff258
2 parents 24cddcc + 46944b0 commit 2f2ce7e

File tree

261 files changed

+455
-534
lines changed

Some content is hidden

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

261 files changed

+455
-534
lines changed

clang/docs/RealtimeSanitizer.rst

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Introduction
99
============
1010
RealtimeSanitizer (a.k.a. RTSan) is a real-time safety testing tool for C and C++
1111
projects. RTSan can be used to detect real-time violations, i.e. calls to methods
12-
that are not safe for use in functions with deterministic runtime requirements.
12+
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. If RTSan detects a call to ``malloc``, ``free``,
1515
``pthread_mutex_lock``, or anything else that could have a non-deterministic
@@ -58,31 +58,71 @@ code.
5858
return 0;
5959
}
6060
# Compile and link
61-
% clang++ -fsanitize=realtime -g example_realtime_violation.cpp
61+
% clang++ -fsanitize=realtime example_realtime_violation.cpp
6262
6363
If a real-time safety violation is detected in a ``[[clang::nonblocking]]``
6464
context, or any function invoked by that function, the program will exit with a
6565
non-zero exit code.
6666

6767
.. code-block:: console
6868
69-
% clang++ -fsanitize=realtime -g example_realtime_violation.cpp
69+
% clang++ -fsanitize=realtime example_realtime_violation.cpp
7070
% ./a.out
71-
Real-time violation: intercepted call to real-time unsafe function `malloc` in real-time context! Stack trace:
72-
#0 0x000102893034 in __rtsan::PrintStackTrace() rtsan_stack.cpp:45
73-
#1 0x000102892e64 in __rtsan::Context::ExpectNotRealtime(char const*) rtsan_context.cpp:78
74-
#2 0x00010289397c in malloc rtsan_interceptors.cpp:286
75-
#3 0x000195bd7bd0 in operator new(unsigned long)+0x1c (libc++abi.dylib:arm64+0x16bd0)
76-
#4 0x5c7f00010230f07c (<unknown module>)
77-
#5 0x00010230f058 in std::__1::__libcpp_allocate[abi:ue170006](unsigned long, unsigned long) new:324
78-
#6 0x00010230effc in std::__1::allocator<float>::allocate[abi:ue170006](unsigned long) allocator.h:114
79-
... snip ...
80-
#10 0x00010230e4bc in std::__1::vector<float, std::__1::allocator<float>>::__append(unsigned long) vector:1162
81-
#11 0x00010230dcdc in std::__1::vector<float, std::__1::allocator<float>>::resize(unsigned long) vector:1981
82-
#12 0x00010230dc28 in violation() main.cpp:5
83-
#13 0x00010230dd64 in main main.cpp:9
84-
#14 0x0001958960dc (<unknown module>)
85-
#15 0x2f557ffffffffffc (<unknown module>)
71+
==76290==ERROR: RealtimeSanitizer: unsafe-library-call
72+
Intercepted call to real-time unsafe function `malloc` in real-time context!
73+
#0 0x000102a7b884 in malloc rtsan_interceptors.cpp:426
74+
#1 0x00019c326bd0 in operator new(unsigned long)+0x1c (libc++abi.dylib:arm64+0x16bd0)
75+
#2 0xa30d0001024f79a8 (<unknown module>)
76+
#3 0x0001024f794c in std::__1::__libcpp_allocate[abi:ne200000](unsigned long, unsigned long)+0x44
77+
#4 0x0001024f78c4 in std::__1::allocator<float>::allocate[abi:ne200000](unsigned long)+0x44
78+
... snip ...
79+
#9 0x0001024f6868 in std::__1::vector<float, std::__1::allocator<float>>::resize(unsigned long)+0x48
80+
#10 0x0001024f67b4 in violation()+0x24
81+
#11 0x0001024f68f0 in main+0x18 (a.out:arm64+0x1000028f0)
82+
#12 0x00019bfe3150 (<unknown module>)
83+
#13 0xed5efffffffffffc (<unknown module>)
84+
85+
86+
Blocking functions
87+
------------------
88+
89+
Calls to system library functions such as ``malloc`` are automatically caught by
90+
RealtimeSanitizer. Real-time programmers may also write their own blocking
91+
(real-time unsafe) functions that they wish RealtimeSanitizer to be aware of.
92+
RealtimeSanitizer will raise an error at run time if any function attributed
93+
with ``[[clang::blocking]]`` is called in a ``[[clang::nonblocking]]`` context.
94+
95+
.. code-block:: console
96+
97+
$ cat example_blocking_violation.cpp
98+
#include <atomic>
99+
#include <thread>
100+
101+
std::atomic<bool> has_permission{false};
102+
103+
int wait_for_permission() [[clang::blocking]] {
104+
while (has_permission.load() == false)
105+
std::this_thread::yield();
106+
return 0;
107+
}
108+
109+
int real_time_function() [[clang::nonblocking]] {
110+
return wait_for_permission();
111+
}
112+
113+
int main() {
114+
return real_time_function();
115+
}
116+
117+
$ clang++ -fsanitize=realtime example_blocking_violation.cpp && ./a.out
118+
==76131==ERROR: RealtimeSanitizer: blocking-call
119+
Call to blocking function `wait_for_permission()` in real-time context!
120+
#0 0x0001000c3db0 in wait_for_permission()+0x10 (a.out:arm64+0x100003db0)
121+
#1 0x0001000c3e3c in real_time_function()+0x10 (a.out:arm64+0x100003e3c)
122+
#2 0x0001000c3e68 in main+0x10 (a.out:arm64+0x100003e68)
123+
#3 0x00019bfe3150 (<unknown module>)
124+
#4 0x5a27fffffffffffc (<unknown module>)
125+
86126
87127
Run-time flags
88128
--------------
@@ -159,7 +199,7 @@ Disabling
159199

160200
In some circumstances, you may want to suppress error reporting in a specific scope.
161201

162-
In C++, this is achieved via ``__rtsan::ScopedDisabler``. Within the scope where the ``ScopedDisabler`` object is instantiated, all sanitizer error reports are suppressed. This suppression applies to the current scope as well as all invoked functions, including any functions called transitively.
202+
In C++, this is achieved via ``__rtsan::ScopedDisabler``. Within the scope where the ``ScopedDisabler`` object is instantiated, all sanitizer error reports are suppressed. This suppression applies to the current scope as well as all invoked functions, including any functions called transitively.
163203

164204
.. code-block:: c++
165205

@@ -174,7 +214,7 @@ In C++, this is achieved via ``__rtsan::ScopedDisabler``. Within the scope wher
174214

175215
If RealtimeSanitizer is not enabled at compile time (i.e., the code is not compiled with the ``-fsanitize=realtime`` flag), the ``ScopedDisabler`` is compiled as a no-op.
176216

177-
In C, you can use the ``__rtsan_disable()`` and ``rtsan_enable()`` functions to manually disable and re-enable RealtimeSanitizer checks.
217+
In C, you can use the ``__rtsan_disable()`` and ``rtsan_enable()`` functions to manually disable and re-enable RealtimeSanitizer checks.
178218

179219
.. code-block:: c++
180220

clang/lib/Basic/TargetID.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,9 @@ parseTargetIDWithFormatCheckingOnly(llvm::StringRef TargetID,
9292
if (Sign != '+' && Sign != '-')
9393
return std::nullopt;
9494
bool IsOn = Sign == '+';
95-
auto Loc = FeatureMap->find(Feature);
9695
// Each feature can only show up at most once in target ID.
97-
if (Loc != FeatureMap->end())
96+
if (!FeatureMap->try_emplace(Feature, IsOn).second)
9897
return std::nullopt;
99-
(*FeatureMap)[Feature] = IsOn;
10098
Features = Splits.second;
10199
}
102100
return Processor;
@@ -147,15 +145,15 @@ getConflictTargetIDCombination(const std::set<llvm::StringRef> &TargetIDs) {
147145
struct Info {
148146
llvm::StringRef TargetID;
149147
llvm::StringMap<bool> Features;
148+
Info(llvm::StringRef TargetID, const llvm::StringMap<bool> &Features)
149+
: TargetID(TargetID), Features(Features) {}
150150
};
151151
llvm::StringMap<Info> FeatureMap;
152152
for (auto &&ID : TargetIDs) {
153153
llvm::StringMap<bool> Features;
154154
llvm::StringRef Proc = *parseTargetIDWithFormatCheckingOnly(ID, &Features);
155-
auto Loc = FeatureMap.find(Proc);
156-
if (Loc == FeatureMap.end())
157-
FeatureMap[Proc] = Info{ID, Features};
158-
else {
155+
auto [Loc, Inserted] = FeatureMap.try_emplace(Proc, ID, Features);
156+
if (!Inserted) {
159157
auto &ExistingFeatures = Loc->second.Features;
160158
if (llvm::any_of(Features, [&](auto &F) {
161159
return ExistingFeatures.count(F.first()) == 0;

flang/include/flang/Optimizer/CodeGen/CodeGen.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ std::unique_ptr<mlir::Pass> createLLVMDialectToLLVMPass(
7272
[](llvm::Module &m, llvm::raw_ostream &out) { m.print(out, nullptr); });
7373

7474
/// Populate the given list with patterns that convert from FIR to LLVM.
75-
void populateFIRToLLVMConversionPatterns(fir::LLVMTypeConverter &converter,
76-
mlir::RewritePatternSet &patterns,
77-
fir::FIRToLLVMPassOptions &options);
75+
void populateFIRToLLVMConversionPatterns(
76+
const fir::LLVMTypeConverter &converter, mlir::RewritePatternSet &patterns,
77+
fir::FIRToLLVMPassOptions &options);
7878

7979
/// Populate the pattern set with the PreCGRewrite patterns.
8080
void populatePreCGRewritePatterns(mlir::RewritePatternSet &patterns,

flang/include/flang/Optimizer/CodeGen/CodeGenOpenMP.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class LLVMTypeConverter;
1919
/// dialect, utilised in cases where the default OpenMP dialect handling cannot
2020
/// handle all cases for intermingled fir types and operations.
2121
void populateOpenMPFIRToLLVMConversionPatterns(
22-
LLVMTypeConverter &converter, mlir::RewritePatternSet &patterns);
22+
const LLVMTypeConverter &converter, mlir::RewritePatternSet &patterns);
2323

2424
} // namespace fir
2525

flang/include/flang/Optimizer/Transforms/CufOpConversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class DataLayout;
2222

2323
namespace cuf {
2424

25-
void populateCUFToFIRConversionPatterns(fir::LLVMTypeConverter &converter,
25+
void populateCUFToFIRConversionPatterns(const fir::LLVMTypeConverter &converter,
2626
mlir::DataLayout &dl,
2727
mlir::RewritePatternSet &patterns);
2828

flang/lib/Optimizer/CodeGen/CodeGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3823,7 +3823,7 @@ fir::createLLVMDialectToLLVMPass(llvm::raw_ostream &output,
38233823
}
38243824

38253825
void fir::populateFIRToLLVMConversionPatterns(
3826-
fir::LLVMTypeConverter &converter, mlir::RewritePatternSet &patterns,
3826+
const fir::LLVMTypeConverter &converter, mlir::RewritePatternSet &patterns,
38273827
fir::FIRToLLVMPassOptions &options) {
38283828
patterns.insert<
38293829
AbsentOpConversion, AddcOpConversion, AddrOfOpConversion,

flang/lib/Optimizer/CodeGen/CodeGenOpenMP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,6 @@ struct MapInfoOpConversion
9393
} // namespace
9494

9595
void fir::populateOpenMPFIRToLLVMConversionPatterns(
96-
LLVMTypeConverter &converter, mlir::RewritePatternSet &patterns) {
96+
const LLVMTypeConverter &converter, mlir::RewritePatternSet &patterns) {
9797
patterns.add<MapInfoOpConversion>(converter);
9898
}

flang/lib/Optimizer/Transforms/CufOpConversion.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ struct CufAllocOpConversion : public mlir::OpRewritePattern<cuf::AllocOp> {
222222
using OpRewritePattern::OpRewritePattern;
223223

224224
CufAllocOpConversion(mlir::MLIRContext *context, mlir::DataLayout *dl,
225-
fir::LLVMTypeConverter *typeConverter)
225+
const fir::LLVMTypeConverter *typeConverter)
226226
: OpRewritePattern(context), dl{dl}, typeConverter{typeConverter} {}
227227

228228
mlir::LogicalResult
@@ -311,7 +311,7 @@ struct CufAllocOpConversion : public mlir::OpRewritePattern<cuf::AllocOp> {
311311

312312
private:
313313
mlir::DataLayout *dl;
314-
fir::LLVMTypeConverter *typeConverter;
314+
const fir::LLVMTypeConverter *typeConverter;
315315
};
316316

317317
struct CufFreeOpConversion : public mlir::OpRewritePattern<cuf::FreeOp> {
@@ -583,7 +583,7 @@ class CufOpConversion : public fir::impl::CufOpConversionBase<CufOpConversion> {
583583
} // namespace
584584

585585
void cuf::populateCUFToFIRConversionPatterns(
586-
fir::LLVMTypeConverter &converter, mlir::DataLayout &dl,
586+
const fir::LLVMTypeConverter &converter, mlir::DataLayout &dl,
587587
mlir::RewritePatternSet &patterns) {
588588
patterns.insert<CufAllocOpConversion>(patterns.getContext(), &dl, &converter);
589589
patterns.insert<CufAllocateOpConversion, CufDeallocateOpConversion,

libc/include/llvm-libc-macros/linux/error-number-macros.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,12 @@
2121
#define EHWPOISON 133
2222
#endif // EHWPOISON
2323

24+
#ifndef EOPNOTSUPP
25+
#define EOPNOTSUPP 95
26+
#endif
27+
28+
#ifndef ENOTSUP
29+
#define ENOTSUP EOPNOTSUPP
30+
#endif
31+
2432
#endif // LLVM_LIBC_MACROS_LINUX_ERROR_NUMBER_MACROS_H

libc/src/__support/StringUtil/tables/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ add_header_library(
33
HDRS
44
stdc_errors.h
55
DEPENDS
6-
libc.include.errno
6+
libc.src.errno.errno
77
libc.src.__support.StringUtil.message_mapper
88
)
99

@@ -12,7 +12,7 @@ add_header_library(
1212
HDRS
1313
posix_errors.h
1414
DEPENDS
15-
libc.include.errno
15+
libc.src.errno.errno
1616
libc.src.__support.StringUtil.message_mapper
1717
)
1818

@@ -21,8 +21,8 @@ add_header_library(
2121
HDRS
2222
linux_extension_errors.h
2323
DEPENDS
24-
libc.include.errno
2524
libc.src.__support.StringUtil.message_mapper
25+
libc.src.errno.errno
2626
)
2727

2828
add_header_library(

libc/src/__support/StringUtil/tables/linux_extension_errors.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
#include "src/__support/StringUtil/message_mapper.h"
1313
#include "src/__support/macros/config.h"
14-
15-
#include <errno.h> // For error macros
14+
#include "src/errno/libc_errno.h"
1615

1716
namespace LIBC_NAMESPACE_DECL {
1817

libc/src/__support/StringUtil/tables/posix_errors.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
#ifndef LLVM_LIBC_SRC___SUPPORT_STRINGUTIL_TABLES_POSIX_ERRORS_H
1010
#define LLVM_LIBC_SRC___SUPPORT_STRINGUTIL_TABLES_POSIX_ERRORS_H
1111

12+
#include "hdr/errno_macros.h"
1213
#include "src/__support/StringUtil/message_mapper.h"
1314
#include "src/__support/macros/config.h"
1415

15-
#include <errno.h> // For error macros
16-
1716
namespace LIBC_NAMESPACE_DECL {
1817

1918
LIBC_INLINE_VAR constexpr MsgTable<76> POSIX_ERRORS = {

libc/src/__support/StringUtil/tables/stdc_errors.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include "src/__support/StringUtil/message_mapper.h"
1313
#include "src/__support/macros/config.h"
1414

15-
#include <errno.h> // For error macros
16-
1715
namespace LIBC_NAMESPACE_DECL {
1816

1917
LIBC_INLINE_VAR constexpr const MsgTable<4> STDC_ERRORS = {

libc/src/math/generic/CMakeLists.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,6 @@ add_entrypoint_object(
13721372
DEPENDS
13731373
.common_constants
13741374
.explogxf
1375-
libc.include.errno
13761375
libc.src.__support.CPP.bit
13771376
libc.src.__support.CPP.optional
13781377
libc.src.__support.FPUtil.dyadic_float
@@ -1406,7 +1405,6 @@ add_entrypoint_object(
14061405
libc.src.__support.FPUtil.polyeval
14071406
libc.src.__support.FPUtil.rounding_mode
14081407
libc.src.__support.macros.optimization
1409-
libc.include.errno
14101408
libc.src.errno.errno
14111409
COMPILE_OPTIONS
14121410
-O3
@@ -1445,7 +1443,6 @@ add_entrypoint_object(
14451443
DEPENDS
14461444
.common_constants
14471445
.explogxf
1448-
libc.include.errno
14491446
libc.src.__support.CPP.bit
14501447
libc.src.__support.CPP.optional
14511448
libc.src.__support.FPUtil.dyadic_float
@@ -1478,7 +1475,6 @@ add_header_library(
14781475
libc.src.__support.FPUtil.rounding_mode
14791476
libc.src.__support.macros.optimization
14801477
libc.src.__support.common
1481-
libc.include.errno
14821478
libc.src.errno.errno
14831479
)
14841480

@@ -1548,7 +1544,6 @@ add_entrypoint_object(
15481544
DEPENDS
15491545
.common_constants
15501546
.explogxf
1551-
libc.include.errno
15521547
libc.src.__support.CPP.bit
15531548
libc.src.__support.CPP.optional
15541549
libc.src.__support.FPUtil.dyadic_float
@@ -1580,7 +1575,6 @@ add_header_library(
15801575
libc.src.__support.FPUtil.rounding_mode
15811576
libc.src.__support.macros.optimization
15821577
libc.src.__support.common
1583-
libc.include.errno
15841578
libc.src.errno.errno
15851579
COMPILE_OPTIONS
15861580
-O3
@@ -1632,7 +1626,6 @@ add_entrypoint_object(
16321626
DEPENDS
16331627
.common_constants
16341628
.explogxf
1635-
libc.include.errno
16361629
libc.src.__support.CPP.bit
16371630
libc.src.__support.CPP.optional
16381631
libc.src.__support.FPUtil.dyadic_float
@@ -1666,7 +1659,6 @@ add_entrypoint_object(
16661659
libc.src.__support.FPUtil.polyeval
16671660
libc.src.__support.FPUtil.rounding_mode
16681661
libc.src.__support.macros.optimization
1669-
libc.include.errno
16701662
libc.src.errno.errno
16711663
COMPILE_OPTIONS
16721664
-O3
@@ -1705,7 +1697,6 @@ add_entrypoint_object(
17051697
.exp10f_impl
17061698
.exp2f_impl
17071699
.explogxf
1708-
libc.include.errno
17091700
libc.src.__support.CPP.bit
17101701
libc.src.__support.CPP.optional
17111702
libc.src.__support.FPUtil.fenv_impl
@@ -4144,7 +4135,6 @@ add_object_library(
41444135
libc.src.__support.FPUtil.nearest_integer
41454136
libc.src.__support.FPUtil.polyeval
41464137
libc.src.__support.common
4147-
libc.include.errno
41484138
libc.src.errno.errno
41494139
COMPILE_OPTIONS
41504140
-O3

libc/src/math/generic/acosf.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#include "src/__support/macros/config.h"
1717
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
1818

19-
#include <errno.h>
20-
2119
#include "inv_trigf_utils.h"
2220

2321
namespace LIBC_NAMESPACE_DECL {

libc/src/math/generic/asinf.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
1818
#include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA
1919

20-
#include <errno.h>
21-
2220
#include "inv_trigf_utils.h"
2321

2422
namespace LIBC_NAMESPACE_DECL {

0 commit comments

Comments
 (0)