Skip to content

Commit f863730

Browse files
authored
merge main into amd-staging (llvm#2052)
2 parents 964dac8 + fa92fcb commit f863730

File tree

217 files changed

+7349
-3166
lines changed

Some content is hidden

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

217 files changed

+7349
-3166
lines changed

clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,15 @@ void MissingStdForwardCheck::registerMatchers(MatchFinder *Finder) {
9292
declRefExpr(to(equalsBoundNode("param"))))));
9393
auto RefToParm = capturesVar(
9494
varDecl(anyOf(hasSameNameAsBoundNode("param"), RefToParmImplicit)));
95-
auto HasRefToParm = hasAnyCapture(RefToParm);
9695

9796
auto CaptureInRef =
9897
allOf(hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByRef),
9998
unless(hasAnyCapture(
10099
capturesVar(varDecl(hasSameNameAsBoundNode("param"))))));
101-
auto CaptureInCopy = allOf(
102-
hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByCopy), HasRefToParm);
103100
auto CaptureByRefExplicit = hasAnyCapture(
104101
allOf(hasCaptureKind(LambdaCaptureKind::LCK_ByRef), RefToParm));
105102

106-
auto CapturedInBody =
107-
lambdaExpr(anyOf(CaptureInRef, CaptureInCopy, CaptureByRefExplicit));
103+
auto CapturedInBody = lambdaExpr(anyOf(CaptureInRef, CaptureByRefExplicit));
108104
auto CapturedInCaptureList = hasAnyCapture(capturesVar(
109105
varDecl(hasInitializer(ignoringParenImpCasts(equalsBoundNode("call"))))));
110106

clang/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,17 @@ check_include_file(sys/resource.h CLANG_HAVE_RLIMITS)
183183
# This check requires _GNU_SOURCE on linux
184184
check_include_file(dlfcn.h CLANG_HAVE_DLFCN_H)
185185
if( CLANG_HAVE_DLFCN_H )
186+
include(CMakePushCheckState)
186187
include(CheckLibraryExists)
187188
include(CheckSymbolExists)
188189
check_library_exists(dl dlopen "" HAVE_LIBDL)
190+
cmake_push_check_state()
189191
if( HAVE_LIBDL )
190192
list(APPEND CMAKE_REQUIRED_LIBRARIES dl)
191193
endif()
192194
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
193195
check_symbol_exists(dladdr dlfcn.h CLANG_HAVE_DLADDR)
194-
list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
195-
if( HAVE_LIBDL )
196-
list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES dl)
197-
endif()
196+
cmake_pop_check_state()
198197
endif()
199198

200199
set(CLANG_RESOURCE_DIR "" CACHE STRING

clang/Maintainers.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ Clang LLVM IR generation
5151
| Anton Korobeynikov
5252
| anton\@korobeynikov.info (email), asl (Phabricator), asl (GitHub)
5353
54+
Clang MLIR generation
55+
~~~~~~~~~~~~~~~~~~~~~
56+
| Andy Kaylor
57+
| akaylor\@nvidia.com (email), AndyKaylor (Discord), AndyKaylor (GitHub)
58+
59+
| Bruno Cardoso Lopes
60+
| bruno.cardoso\@gmail.com (email), sonicsprawl (Discord), bcardosolopes (GitHub)
61+
5462

5563
Analysis & CFG
5664
~~~~~~~~~~~~~~
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This file sets up a CMakeCache for the second stage of a Fuchsia toolchain build.
2+
3+
include(${CMAKE_CURRENT_LIST_DIR}/Fuchsia-stage2.cmake)
4+
5+
if(NOT APPLE)
6+
set(BOOTSTRAP_LLVM_ENABLE_LLD ON CACHE BOOL "")
7+
endif()
8+
9+
set(CLANG_BOOTSTRAP_TARGETS
10+
check-all
11+
check-clang
12+
check-lld
13+
check-llvm
14+
check-polly
15+
clang
16+
clang-test-depends
17+
toolchain-distribution
18+
install-toolchain-distribution
19+
install-toolchain-distribution-stripped
20+
install-toolchain-distribution-toolchain
21+
lld-test-depends
22+
llvm-config
23+
llvm-test-depends
24+
test-depends
25+
test-suite CACHE STRING "")
26+
27+
get_cmake_property(variableNames VARIABLES)
28+
foreach(variableName ${variableNames})
29+
if(variableName MATCHES "^STAGE2_")
30+
string(REPLACE "STAGE2_" "" new_name ${variableName})
31+
list(APPEND EXTRA_ARGS "-D${new_name}=${${variableName}}")
32+
endif()
33+
endforeach()
34+
35+
set(CLANG_PGO_TRAINING_DEPS
36+
builtins
37+
runtimes
38+
CACHE STRING "")
39+
40+
# Setup the bootstrap build.
41+
set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
42+
set(CLANG_BOOTSTRAP_CMAKE_ARGS
43+
${EXTRA_ARGS}
44+
-C ${CMAKE_CURRENT_LIST_DIR}/Fuchsia-stage2.cmake
45+
CACHE STRING "")

clang/cmake/caches/Fuchsia.cmake

Lines changed: 78 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ else()
126126
set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
127127
set(LIBCXX_HARDENING_MODE "none" CACHE STRING "")
128128
set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
129+
set(COMPILER_RT_BUILD_LIBFUZZER OFF CACHE BOOL "")
130+
set(COMPILER_RT_BUILD_PROFILE ON CACHE BOOL "")
131+
set(COMPILER_RT_BUILD_SANITIZERS OFF CACHE BOOL "")
132+
set(COMPILER_RT_BUILD_XRAY OFF CACHE BOOL "")
133+
set(COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "")
134+
set(COMPILER_RT_DEFAULT_TARGET_ONLY ON CACHE BOOL "")
135+
set(SANITIZER_CXX_ABI "libc++" CACHE STRING "")
136+
set(SANITIZER_CXX_ABI_INTREE ON CACHE BOOL "")
137+
set(SANITIZER_TEST_CXX "libc++" CACHE STRING "")
138+
set(SANITIZER_TEST_CXX_INTREE ON CACHE BOOL "")
129139
set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
130140
set(RUNTIMES_CMAKE_ARGS "-DCMAKE_OSX_DEPLOYMENT_TARGET=10.13;-DCMAKE_OSX_ARCHITECTURES=arm64|x86_64" CACHE STRING "")
131141
endif()
@@ -165,33 +175,59 @@ endif()
165175
set(BOOTSTRAP_LLVM_ENABLE_LLD ON CACHE BOOL "")
166176
set(BOOTSTRAP_LLVM_ENABLE_LTO ON CACHE BOOL "")
167177

168-
set(_FUCHSIA_BOOTSTRAP_TARGETS
169-
check-all
170-
check-clang
171-
check-lld
172-
check-llvm
173-
check-polly
174-
llvm-config
175-
clang-test-depends
176-
lld-test-depends
177-
llvm-test-depends
178-
test-suite
179-
test-depends
180-
toolchain-distribution
181-
install-toolchain-distribution
182-
install-toolchain-distribution-stripped
183-
install-toolchain-distribution-toolchain
184-
clang)
185-
186-
if(FUCHSIA_ENABLE_LLDB)
187-
list(APPEND _FUCHSIA_ENABLE_PROJECTS lldb)
188-
list(APPEND _FUCHSIA_BOOTSTRAP_TARGETS
189-
check-lldb
190-
lldb-test-depends
191-
debugger-distribution
192-
install-debugger-distribution
193-
install-debugger-distribution-stripped
194-
install-debugger-distribution-toolchain)
178+
if(FUCHSIA_ENABLE_PGO)
179+
set(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED ON CACHE BOOL "")
180+
181+
set(_FUCHSIA_BOOTSTRAP_TARGETS
182+
generate-profdata
183+
stage2
184+
stage2-toolchain-distribution
185+
stage2-install-toolchain-distribution
186+
stage2-install-toolchain-distribution-stripped
187+
stage2-install-toolchain-distribution-toolchain
188+
stage2-check-all
189+
stage2-check-clang
190+
stage2-check-lld
191+
stage2-check-llvm
192+
stage2-check-polly
193+
stage2-test-suite)
194+
if(FUCHSIA_ENABLE_LLDB)
195+
list(APPEND _FUCHSIA_ENABLE_PROJECTS lldb)
196+
list(APPEND _FUCHSIA_BOOTSTRAP_TARGETS
197+
stage2-check-lldb
198+
stage2-debugger-distribution
199+
stage2-install-debugger-distribution
200+
stage2-install-debugger-distribution-stripped
201+
stage2-install-debugger-distribution-toolchain)
202+
endif()
203+
else()
204+
set(_FUCHSIA_BOOTSTRAP_TARGETS
205+
check-all
206+
check-clang
207+
check-lld
208+
check-llvm
209+
check-polly
210+
llvm-config
211+
clang
212+
clang-test-depends
213+
lld-test-depends
214+
llvm-test-depends
215+
test-suite
216+
test-depends
217+
toolchain-distribution
218+
install-toolchain-distribution
219+
install-toolchain-distribution-stripped
220+
install-toolchain-distribution-toolchain)
221+
if(FUCHSIA_ENABLE_LLDB)
222+
list(APPEND _FUCHSIA_ENABLE_PROJECTS lldb)
223+
list(APPEND _FUCHSIA_BOOTSTRAP_TARGETS
224+
check-lldb
225+
lldb-test-depends
226+
debugger-distribution
227+
install-debugger-distribution
228+
install-debugger-distribution-stripped
229+
install-debugger-distribution-toolchain)
230+
endif()
195231
endif()
196232

197233
set(LLVM_ENABLE_PROJECTS ${_FUCHSIA_ENABLE_PROJECTS} CACHE STRING "")
@@ -200,6 +236,7 @@ set(CLANG_BOOTSTRAP_TARGETS ${_FUCHSIA_BOOTSTRAP_TARGETS} CACHE STRING "")
200236
get_cmake_property(variableNames VARIABLES)
201237
foreach(variableName ${variableNames})
202238
if(variableName MATCHES "^STAGE2_")
239+
list(APPEND EXTRA_ARGS "-D${variableName}=${${variableName}}")
203240
string(REPLACE "STAGE2_" "" new_name ${variableName})
204241
string(REPLACE ";" "|" value "${${variableName}}")
205242
list(APPEND EXTRA_ARGS "-D${new_name}=${value}")
@@ -209,13 +246,23 @@ endforeach()
209246
# TODO: This is a temporary workaround until we figure out the right solution.
210247
set(BOOTSTRAP_LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
211248

249+
set(LLVM_BUILTIN_TARGETS "default" CACHE STRING "")
250+
set(LLVM_RUNTIME_TARGETS "default" CACHE STRING "")
251+
212252
# Setup the bootstrap build.
213253
set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
214254
set(CLANG_BOOTSTRAP_EXTRA_DEPS
215255
builtins
216256
runtimes
217257
CACHE STRING "")
218-
set(CLANG_BOOTSTRAP_CMAKE_ARGS
219-
${EXTRA_ARGS}
220-
-C ${CMAKE_CURRENT_LIST_DIR}/Fuchsia-stage2.cmake
221-
CACHE STRING "")
258+
if(FUCHSIA_ENABLE_PGO)
259+
set(CLANG_BOOTSTRAP_CMAKE_ARGS
260+
${EXTRA_ARGS}
261+
-C ${CMAKE_CURRENT_LIST_DIR}/Fuchsia-stage2-instrumented.cmake
262+
CACHE STRING "")
263+
else()
264+
set(CLANG_BOOTSTRAP_CMAKE_ARGS
265+
${EXTRA_ARGS}
266+
-C ${CMAKE_CURRENT_LIST_DIR}/Fuchsia-stage2.cmake
267+
CACHE STRING "")
268+
endif()

clang/docs/HIPSupport.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ Predefined Macros
518518
* - ``__HIPSTDPAR__``
519519
- Defined when Clang is compiling code in algorithm offload mode, enabled
520520
with the ``--hipstdpar`` compiler option.
521-
* - ``__HIPSTDPAR_INTERPOSE_ALLOC__``
521+
* - ``__HIPSTDPAR_INTERPOSE_ALLOC__`` / ``__HIPSTDPAR_INTERPOSE_ALLOC_V1__``
522522
- Defined only when compiling in algorithm offload mode, when the user
523523
enables interposition mode with the ``--hipstdpar-interpose-alloc``
524524
compiler option, indicating that all dynamic memory allocation /

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,9 @@ Improvements to Clang's diagnostics
434434
- The ``-Wsign-compare`` warning now treats expressions with bitwise not(~) and minus(-) as signed integers
435435
except for the case where the operand is an unsigned integer
436436
and throws warning if they are compared with unsigned integers (##18878).
437-
- The ``-Wunnecessary-virtual-specifier`` warning has been added to warn about
438-
methods which are marked as virtual inside a ``final`` class, and hence can
439-
never be overridden.
437+
- The ``-Wunnecessary-virtual-specifier`` warning (included in ``-Wextra``) has
438+
been added to warn about methods which are marked as virtual inside a
439+
``final`` class, and hence can never be overridden.
440440

441441
- Improve the diagnostics for chained comparisons to report actual expressions and operators (#GH129069).
442442

@@ -676,6 +676,8 @@ Bug Fixes to C++ Support
676676
- Fixed a crash when forming an invalid function type in a dependent context. (#GH138657) (#GH115725) (#GH68852)
677677
- No longer crashes when instantiating invalid variable template specialization
678678
whose type depends on itself. (#GH51347), (#GH55872)
679+
- Improved parser recovery of invalid requirement expressions. In turn, this
680+
fixes crashes from follow-on processing of the invalid requirement. (#GH138820)
679681

680682
Bug Fixes to AST Handling
681683
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/docs/SanitizerCoverage.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,50 @@ Users need to implement a single function to capture the CF table at startup:
385385
// the collected control flow.
386386
}
387387
388+
Tracing Stack Depth
389+
===================
390+
391+
With ``-fsanitize-coverage=stack-depth`` the compiler will track how much
392+
stack space has been used for a function call chain. Leaf functions are
393+
not included in this tracing.
394+
395+
The maximum depth of a function call graph is stored in the thread-local
396+
``__sancov_lowest_stack`` variable. Instrumentation is inserted in every
397+
non-leaf function to check the frame pointer against this variable,
398+
and if it is lower, store the current frame pointer. This effectively
399+
inserts the following:
400+
401+
.. code-block:: c++
402+
403+
extern thread_local uintptr_t __sancov_lowest_stack;
404+
405+
uintptr_t stack = (uintptr_t)__builtin_frame_address(0);
406+
if (stack < __sancov_lowest_stack)
407+
__sancov_lowest_stack = stack;
408+
409+
If ``-fsanitize-coverage-stack-depth-callback-min=N`` (where
410+
``N > 0``) is also used, the tracking is delegated to a callback,
411+
``__sanitizer_cov_stack_depth``, instead of adding instrumentation to
412+
update ``__sancov_lowest_stack``. The ``N`` of the argument is used
413+
to determine which functions to instrument. Only functions estimated
414+
to be using ``N`` bytes or more of stack space will be instrumented to
415+
call the tracing callback. In the case of a dynamically sized stack,
416+
the callback is unconditionally added.
417+
418+
The callback takes no arguments and is responsible for determining
419+
the stack usage and doing any needed comparisons and storage. A roughly
420+
equivalent implementation of ``__sancov_lowest_stack`` using the callback
421+
would look like this:
422+
423+
.. code-block:: c++
424+
425+
void __sanitizer_cov_stack_depth(void) {
426+
uintptr_t stack = (uintptr_t)__builtin_frame_address(0);
427+
428+
if (stack < __sancov_lowest_stack)
429+
__sancov_lowest_stack = stack;
430+
}
431+
388432
Gated Trace Callbacks
389433
=====================
390434

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ CODEGENOPT(SanitizeCoveragePCTable, 1, 0) ///< Create a PC Table.
305305
CODEGENOPT(SanitizeCoverageControlFlow, 1, 0) ///< Collect control flow
306306
CODEGENOPT(SanitizeCoverageNoPrune, 1, 0) ///< Disable coverage pruning.
307307
CODEGENOPT(SanitizeCoverageStackDepth, 1, 0) ///< Enable max stack depth tracing
308+
VALUE_CODEGENOPT(SanitizeCoverageStackDepthCallbackMin , 32, 0) ///< Enable stack depth tracing callbacks.
308309
CODEGENOPT(SanitizeCoverageTraceLoads, 1, 0) ///< Enable tracing of loads.
309310
CODEGENOPT(SanitizeCoverageTraceStores, 1, 0) ///< Enable tracing of stores.
310311
CODEGENOPT(SanitizeBinaryMetadataCovered, 1, 0) ///< Emit PCs for covered functions.

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,13 +421,12 @@ def CXX11WarnSuggestOverride : DiagGroup<"suggest-override">;
421421
def WarnUnnecessaryVirtualSpecifier : DiagGroup<"unnecessary-virtual-specifier"> {
422422
code Documentation = [{
423423
Warns when a ``final`` class contains a virtual method (including virtual
424-
destructors). Since ``final`` classes cannot be subclassed, their methods
425-
cannot be overridden, and hence the ``virtual`` specifier is useless.
424+
destructors) that does not override anything. Since ``final`` classes cannot
425+
be subclassed, their methods cannot be overridden, so there is no point to
426+
introducing new ``virtual`` methods.
426427

427428
The warning also detects virtual methods in classes whose destructor is
428429
``final``, for the same reason.
429-
430-
The warning does not fire on virtual methods which are also marked ``override``.
431430
}];
432431
}
433432

@@ -1164,6 +1163,7 @@ def Extra : DiagGroup<"extra", [
11641163
FUseLdPath,
11651164
CastFunctionTypeMismatch,
11661165
InitStringTooLongMissingNonString,
1166+
WarnUnnecessaryVirtualSpecifier,
11671167
]>;
11681168

11691169
def Most : DiagGroup<"most", [

clang/include/clang/CIR/CIRToCIRPasses.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ namespace cir {
3232
mlir::LogicalResult runCIRToCIRPasses(mlir::ModuleOp theModule,
3333
mlir::MLIRContext &mlirCtx,
3434
clang::ASTContext &astCtx,
35-
bool enableVerifier);
35+
bool enableVerifier,
36+
bool enableCIRSimplify);
3637

3738
} // namespace cir
3839

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
111111
cir::BoolType getBoolTy() { return cir::BoolType::get(getContext()); }
112112

113113
cir::PointerType getPointerTo(mlir::Type ty) {
114-
return cir::PointerType::get(getContext(), ty);
114+
return cir::PointerType::get(ty);
115115
}
116116

117117
cir::PointerType getVoidPtrTy() {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ def CIR_Dialect : Dialect {
2727
let useDefaultAttributePrinterParser = 0;
2828
let useDefaultTypePrinterParser = 0;
2929

30+
// Enable constant materialization for the CIR dialect. This generates a
31+
// declaration for the cir::CIRDialect::materializeConstant function. This
32+
// hook is necessary for canonicalization to properly handle attributes
33+
// returned by fold methods, allowing them to be materialized as constant
34+
// operations in the IR.
35+
let hasConstantMaterializer = 1;
36+
3037
let extraClassDeclaration = [{
3138
static llvm::StringRef getTripleAttrName() { return "cir.triple"; }
3239

0 commit comments

Comments
 (0)