Skip to content

Commit a46f4da

Browse files
authored
LLVM and SPIRV-LLVM-Translator pulldown (WW38)(#2468)
LLVM: llvm/llvm-project@8b30067 SPIRV-LLVM-Translator: KhronosGroup/SPIRV-LLVM-Translator@48c6ff6
2 parents 93081e1 + 4f76639 commit a46f4da

File tree

1,010 files changed

+24305
-11688
lines changed

Some content is hidden

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

1,010 files changed

+24305
-11688
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ autoconf/autom4te.cache
5454
# VS2017 and VSCode config files.
5555
.vscode
5656
.vs
57+
# pythonenv for github Codespaces
58+
pythonenv*
5759
# clangd index. (".clangd" is a config file now, thus trailing slash)
5860
.clangd/
5961
.cache

clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ void UseAutoCheck::replaceIterators(const DeclStmt *D, ASTContext *Context) {
338338

339339
// Drill down to the as-written initializer.
340340
const Expr *E = (*Construct->arg_begin())->IgnoreParenImpCasts();
341-
if (E != E->IgnoreConversionOperator()) {
341+
if (E != E->IgnoreConversionOperatorSingleStep()) {
342342
// We hit a conversion operator. Early-out now as they imply an implicit
343343
// conversion from a different type. Could also mean an explicit
344344
// conversion from the same type but that's pretty rare.

clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ std::string compareExpressionToZero(const MatchFinder::MatchResult &Result,
205205

206206
std::string replacementExpression(const MatchFinder::MatchResult &Result,
207207
bool Negated, const Expr *E) {
208-
E = E->ignoreParenBaseCasts();
208+
E = E->IgnoreParenBaseCasts();
209209
if (const auto *EC = dyn_cast<ExprWithCleanups>(E))
210210
E = EC->getSubExpr();
211211

clang-tools-extra/docs/clang-tidy/checks/bugprone-redundant-branch-condition.rst

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ Known limitations
8383

8484
The ``else`` branch is not checked currently for negated condition variable:
8585

86+
.. code-block:: c
87+
8688
bool onFire = isBurning();
8789
if (onFire) {
8890
scream();

clang/docs/Block-ABI-Apple.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ High Level
3535
==========
3636

3737
The ABI of ``Blocks`` consist of their layout and the runtime functions required
38-
by the compiler. A ``Block`` consists of a structure of the following form:
38+
by the compiler. A ``Block`` of type ``R (^)(P...)`` consists of a structure of
39+
the following form:
3940

4041
.. code-block:: c
4142
4243
struct Block_literal_1 {
4344
void *isa; // initialized to &_NSConcreteStackBlock or &_NSConcreteGlobalBlock
4445
int flags;
4546
int reserved;
46-
void (*invoke)(void *, ...);
47+
R (*invoke)(struct Block_literal_1 *, P...);
4748
struct Block_descriptor_1 {
4849
unsigned long int reserved; // NULL
4950
unsigned long int size; // sizeof(struct Block_literal_1)

clang/docs/ClangFormatStyleOptions.rst

+17
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,24 @@ the configuration (without a prefix: ``Auto``).
758758
int bbbbbbbbbbbbbbbbbbbbb) {
759759
}
760760

761+
**AttributeMacros** (``std::vector<std::string>``)
762+
A vector of strings that should be interpreted as attributes/qualifiers
763+
instead of identifiers. This can be useful for language extensions or
764+
static analyzer annotations:
761765

766+
.. code-block:: c++
767+
768+
x = (char *__capability)&y;
769+
int function(void) __ununsed;
770+
void only_writes_to_buffer(char *__output buffer);
771+
772+
In the .clang-format configuration file, this can be configured like:
773+
774+
.. code-block:: yaml
775+
776+
AttributeMacros: ['__capability', '__output', '__ununsed']
777+
778+
For example: __capability.
762779

763780
**BinPackArguments** (``bool``)
764781
If ``false``, a function call's arguments will either be all on the

clang/docs/ThreadSafetyAnalysis.rst

+103-11
Original file line numberDiff line numberDiff line change
@@ -209,21 +209,21 @@ must be held on entry to the function, *and must still be held on exit*.
209209
}
210210

211211

212-
ACQUIRE(...), ACQUIRE_SHARED(...), RELEASE(...), RELEASE_SHARED(...)
213-
--------------------------------------------------------------------
212+
ACQUIRE(...), ACQUIRE_SHARED(...), RELEASE(...), RELEASE_SHARED(...), RELEASE_GENERIC(...)
213+
------------------------------------------------------------------------------------------
214214

215215
*Previously*: ``EXCLUSIVE_LOCK_FUNCTION``, ``SHARED_LOCK_FUNCTION``,
216216
``UNLOCK_FUNCTION``
217217

218-
``ACQUIRE`` is an attribute on functions or methods, which
219-
declares that the function acquires a capability, but does not release it. The
220-
caller must not hold the given capability on entry, and it will hold the
221-
capability on exit. ``ACQUIRE_SHARED`` is similar.
218+
``ACQUIRE`` and ``ACQUIRE_SHARED`` are attributes on functions or methods
219+
declaring that the function acquires a capability, but does not release it.
220+
The given capability must not be held on entry, and will be held on exit
221+
(exclusively for ``ACQUIRE``, shared for ``ACQUIRE_SHARED``).
222222

223-
``RELEASE`` and ``RELEASE_SHARED`` declare that the function releases the given
224-
capability. The caller must hold the capability on entry, and will no longer
225-
hold it on exit. It does not matter whether the given capability is shared or
226-
exclusive.
223+
``RELEASE``, ``RELEASE_SHARED``, and ``RELEASE_GENERIC`` declare that the
224+
function releases the given capability. The capability must be held on entry
225+
(exclusively for ``RELEASE``, shared for ``RELEASE_SHARED``, exclusively or
226+
shared for ``RELEASE_GENERIC``), and will no longer be held on exit.
227227

228228
.. code-block:: c++
229229

@@ -402,6 +402,13 @@ the destructor. Such classes require special handling because the constructor
402402
and destructor refer to the capability via different names; see the
403403
``MutexLocker`` class in :ref:`mutexheader`, below.
404404

405+
Scoped capabilities are treated as capabilities that are implicitly acquired
406+
on construction and released on destruction. They are associated with
407+
the set of (regular) capabilities named in thread safety attributes on the
408+
constructor. Acquire-type attributes on other member functions are treated as
409+
applying to that set of associated capabilities, while ``RELEASE`` implies that
410+
a function releases all associated capabilities in whatever mode they're held.
411+
405412

406413
TRY_ACQUIRE(<bool>, ...), TRY_ACQUIRE_SHARED(<bool>, ...)
407414
---------------------------------------------------------
@@ -414,6 +421,26 @@ The first argument must be ``true`` or ``false``, to specify which return value
414421
indicates success, and the remaining arguments are interpreted in the same way
415422
as ``ACQUIRE``. See :ref:`mutexheader`, below, for example uses.
416423

424+
Because the analysis doesn't support conditional locking, a capability is
425+
treated as acquired after the first branch on the return value of a try-acquire
426+
function.
427+
428+
.. code-block:: c++
429+
430+
Mutex mu;
431+
int a GUARDED_BY(mu);
432+
433+
void foo() {
434+
bool success = mu.TryLock();
435+
a = 0; // Warning, mu is not locked.
436+
if (success) {
437+
a = 0; // Ok.
438+
mu.Unlock();
439+
} else {
440+
a = 0; // Warning, mu is not locked.
441+
}
442+
}
443+
417444

418445
ASSERT_CAPABILITY(...) and ASSERT_SHARED_CAPABILITY(...)
419446
--------------------------------------------------------
@@ -800,6 +827,9 @@ implementation.
800827
#define RELEASE_SHARED(...) \
801828
THREAD_ANNOTATION_ATTRIBUTE__(release_shared_capability(__VA_ARGS__))
802829

830+
#define RELEASE_GENERIC(...) \
831+
THREAD_ANNOTATION_ATTRIBUTE__(release_generic_capability(__VA_ARGS__))
832+
803833
#define TRY_ACQUIRE(...) \
804834
THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_capability(__VA_ARGS__))
805835

@@ -844,6 +874,9 @@ implementation.
844874
// Release/unlock a shared mutex.
845875
void ReaderUnlock() RELEASE_SHARED();
846876

877+
// Generic unlock, can unlock exclusive and shared mutexes.
878+
void GenericUnlock() RELEASE_GENERIC();
879+
847880
// Try to acquire the mutex. Returns true on success, and false on failure.
848881
bool TryLock() TRY_ACQUIRE(true);
849882

@@ -860,19 +893,78 @@ implementation.
860893
const Mutex& operator!() const { return *this; }
861894
};
862895
896+
// Tag types for selecting a constructor.
897+
struct adopt_lock_t {} inline constexpr adopt_lock = {};
898+
struct defer_lock_t {} inline constexpr defer_lock = {};
899+
struct shared_lock_t {} inline constexpr shared_lock = {};
863900

864901
// MutexLocker is an RAII class that acquires a mutex in its constructor, and
865902
// releases it in its destructor.
866903
class SCOPED_CAPABILITY MutexLocker {
867904
private:
868905
Mutex* mut;
906+
bool locked;
869907

870908
public:
871-
MutexLocker(Mutex *mu) ACQUIRE(mu) : mut(mu) {
909+
// Acquire mu, implicitly acquire *this and associate it with mu.
910+
MutexLocker(Mutex *mu) ACQUIRE(mu) : mut(mu), locked(true) {
872911
mu->Lock();
873912
}
913+
914+
// Assume mu is held, implicitly acquire *this and associate it with mu.
915+
MutexLocker(Mutex *mu, adopt_lock_t) REQUIRES(mu) : mut(mu), locked(true) {}
916+
917+
// Acquire mu in shared mode, implicitly acquire *this and associate it with mu.
918+
MutexLocker(Mutex *mu, shared_lock_t) ACQUIRE_SHARED(mu) : mut(mu), locked(true) {
919+
mu->ReaderLock();
920+
}
921+
922+
// Assume mu is held in shared mode, implicitly acquire *this and associate it with mu.
923+
MutexLocker(Mutex *mu, adopt_lock_t, shared_lock_t) REQUIRES_SHARED(mu)
924+
: mut(mu), locked(true) {}
925+
926+
// Assume mu is not held, implicitly acquire *this and associate it with mu.
927+
MutexLocker(Mutex *mu, defer_lock_t) EXCLUDES(mu) : mut(mu), locked(false) {}
928+
929+
// Release *this and all associated mutexes, if they are still held.
930+
// There is no warning if the scope was already unlocked before.
874931
~MutexLocker() RELEASE() {
932+
if (locked)
933+
mut->GenericUnlock();
934+
}
935+
936+
// Acquire all associated mutexes exclusively.
937+
void Lock() ACQUIRE() {
938+
mut->Lock();
939+
locked = true;
940+
}
941+
942+
// Try to acquire all associated mutexes exclusively.
943+
bool TryLock() TRY_ACQUIRE(true) {
944+
return locked = mut->TryLock();
945+
}
946+
947+
// Acquire all associated mutexes in shared mode.
948+
void ReaderLock() ACQUIRE_SHARED() {
949+
mut->ReaderLock();
950+
locked = true;
951+
}
952+
953+
// Try to acquire all associated mutexes in shared mode.
954+
bool ReaderTryLock() TRY_ACQUIRE_SHARED(true) {
955+
return locked = mut->ReaderTryLock();
956+
}
957+
958+
// Release all associated mutexes. Warn on double unlock.
959+
void Unlock() RELEASE() {
875960
mut->Unlock();
961+
locked = false;
962+
}
963+
964+
// Release all associated mutexes. Warn on double unlock.
965+
void ReaderUnlock() RELEASE() {
966+
mut->ReaderUnlock();
967+
locked = false;
876968
}
877969
};
878970

clang/docs/analyzer/checkers.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,7 @@ Check for integer to enumeration casts that could result in undefined values.
17471747
void foo() {
17481748
TestEnum t = static_cast(-1);
17491749
// warn: the value provided to the cast expression is not in
1750-
the valid range of values for the enum
1750+
// the valid range of values for the enum
17511751
17521752
.. _alpha-cplusplus-InvalidatedIterator:
17531753

clang/examples/Attribute/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
add_llvm_library(Attribute MODULE Attribute.cpp PLUGIN_TOOL clang)
22

33
if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
4-
target_link_libraries(Attribute ${cmake_2_8_12_PRIVATE}
4+
target_link_libraries(Attribute PRIVATE
55
clangAST
66
clangBasic
77
clangFrontend

clang/include/clang-c/Index.h

+20
Original file line numberDiff line numberDiff line change
@@ -2940,6 +2940,26 @@ CINDEX_LINKAGE int clang_getCursorPlatformAvailability(
29402940
CINDEX_LINKAGE void
29412941
clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability);
29422942

2943+
/**
2944+
* If cursor refers to a variable declaration and it has initializer returns
2945+
* cursor referring to the initializer otherwise return null cursor.
2946+
*/
2947+
CINDEX_LINKAGE CXCursor clang_Cursor_getVarDeclInitializer(CXCursor cursor);
2948+
2949+
/**
2950+
* If cursor refers to a variable declaration that has global storage returns 1.
2951+
* If cursor refers to a variable declaration that doesn't have global storage
2952+
* returns 0. Otherwise returns -1.
2953+
*/
2954+
CINDEX_LINKAGE int clang_Cursor_hasVarDeclGlobalStorage(CXCursor cursor);
2955+
2956+
/**
2957+
* If cursor refers to a variable declaration that has external storage
2958+
* returns 1. If cursor refers to a variable declaration that doesn't have
2959+
* external storage returns 0. Otherwise returns -1.
2960+
*/
2961+
CINDEX_LINKAGE int clang_Cursor_hasVarDeclExternalStorage(CXCursor cursor);
2962+
29432963
/**
29442964
* Describe the "language" of the entity referred to by a cursor.
29452965
*/

clang/include/clang-c/Rewrite.h

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*===-- clang-c/Rewrite.h - C CXRewriter --------------------------*- C -*-===*\
2+
|* *|
3+
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4+
|* Exceptions. *|
5+
|* See https://llvm.org/LICENSE.txt for license information. *|
6+
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7+
|* *|
8+
|*===----------------------------------------------------------------------===*/
9+
10+
#ifndef LLVM_CLANG_C_REWRITE_H
11+
#define LLVM_CLANG_C_REWRITE_H
12+
13+
#include "clang-c/CXString.h"
14+
#include "clang-c/ExternC.h"
15+
#include "clang-c/Index.h"
16+
#include "clang-c/Platform.h"
17+
18+
LLVM_CLANG_C_EXTERN_C_BEGIN
19+
20+
typedef void *CXRewriter;
21+
22+
/**
23+
* Create CXRewriter.
24+
*/
25+
CINDEX_LINKAGE CXRewriter clang_CXRewriter_create(CXTranslationUnit TU);
26+
27+
/**
28+
* Insert the specified string at the specified location in the original buffer.
29+
*/
30+
CINDEX_LINKAGE void clang_CXRewriter_insertTextBefore(CXRewriter Rew, CXSourceLocation Loc,
31+
const char *Insert);
32+
33+
/**
34+
* Replace the specified range of characters in the input with the specified
35+
* replacement.
36+
*/
37+
CINDEX_LINKAGE void clang_CXRewriter_replaceText(CXRewriter Rew, CXSourceRange ToBeReplaced,
38+
const char *Replacement);
39+
40+
/**
41+
* Remove the specified range.
42+
*/
43+
CINDEX_LINKAGE void clang_CXRewriter_removeText(CXRewriter Rew, CXSourceRange ToBeRemoved);
44+
45+
/**
46+
* Save all changed files to disk.
47+
* Returns 1 if any files were not saved successfully, returns 0 otherwise.
48+
*/
49+
CINDEX_LINKAGE int clang_CXRewriter_overwriteChangedFiles(CXRewriter Rew);
50+
51+
/**
52+
* Write out rewritten version of the main file to stdout.
53+
*/
54+
CINDEX_LINKAGE void clang_CXRewriter_writeMainFileToStdOut(CXRewriter Rew);
55+
56+
/**
57+
* Free the given CXRewriter.
58+
*/
59+
CINDEX_LINKAGE void clang_CXRewriter_dispose(CXRewriter Rew);
60+
61+
LLVM_CLANG_C_EXTERN_C_END
62+
63+
#endif

clang/include/clang/AST/APValue.h

+4-7
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ class APValue {
304304
MakeComplexFloat(); setComplexFloat(std::move(R), std::move(I));
305305
}
306306
APValue(const APValue &RHS);
307-
APValue(APValue &&RHS) : Kind(None) { swap(RHS); }
307+
APValue(APValue &&RHS);
308308
APValue(LValueBase B, const CharUnits &O, NoLValuePath N,
309309
bool IsNullPtr = false)
310310
: Kind(None) {
@@ -339,6 +339,9 @@ class APValue {
339339
return Result;
340340
}
341341

342+
APValue &operator=(const APValue &RHS);
343+
APValue &operator=(APValue &&RHS);
344+
342345
~APValue() {
343346
if (Kind != None && Kind != Indeterminate)
344347
DestroyDataAndMakeUninit();
@@ -591,12 +594,6 @@ class APValue {
591594
((AddrLabelDiffData*)(char*)Data.buffer)->RHSExpr = RHSExpr;
592595
}
593596

594-
/// Assign by swapping from a copy of the RHS.
595-
APValue &operator=(APValue RHS) {
596-
swap(RHS);
597-
return *this;
598-
}
599-
600597
private:
601598
void DestroyDataAndMakeUninit();
602599
void MakeInt() {

0 commit comments

Comments
 (0)