Skip to content

Commit 23bbdfe

Browse files
committed
merge main into amd-staging
Change-Id: Iff4e1c6b02e1b0db2313407f110d04a5b3360853
2 parents e639764 + 2c376fe commit 23bbdfe

File tree

178 files changed

+2853
-1697
lines changed

Some content is hidden

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

178 files changed

+2853
-1697
lines changed

clang/bindings/python/clang/cindex.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4077,6 +4077,7 @@ def function_exists(self, name):
40774077
conf = Config()
40784078

40794079
__all__ = [
4080+
"AccessSpecifier",
40804081
"AvailabilityKind",
40814082
"BinaryOperator",
40824083
"Config",
@@ -4087,12 +4088,16 @@ def function_exists(self, name):
40874088
"CursorKind",
40884089
"Cursor",
40894090
"Diagnostic",
4091+
"ExceptionSpecificationKind",
40904092
"File",
40914093
"FixIt",
40924094
"Index",
40934095
"LinkageKind",
4096+
"RefQualifierKind",
40944097
"SourceLocation",
40954098
"SourceRange",
4099+
"StorageClass",
4100+
"TemplateArgumentKind",
40964101
"TLSKind",
40974102
"TokenKind",
40984103
"Token",

clang/docs/ReleaseNotes.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ Improvements to Clang's diagnostics
137137
template <typename> int i; // error: non-static data member 'i' cannot be declared as a template
138138
};
139139

140+
- Clang now has improved diagnostics for functions with explicit 'this' parameters. Fixes #GH97878
141+
140142
- Clang now diagnoses dangling references to fields of temporary objects. Fixes #GH81589.
141143

142144
- Clang now diagnoses undefined behavior in constant expressions more consistently. This includes invalid shifts, and signed overflow in arithmetic.
@@ -166,6 +168,8 @@ Bug Fixes to C++ Support
166168

167169
- Fixed a crash when an expression with a dependent ``__typeof__`` type is used as the operand of a unary operator. (#GH97646)
168170
- Fixed a failed assertion when checking invalid delete operator declaration. (#GH96191)
171+
- Fix a crash when checking destructor reference with an invalid initializer. (#GH97230)
172+
- Clang now correctly parses potentially declarative nested-name-specifiers in pointer-to-member declarators.
169173

170174
Bug Fixes to AST Handling
171175
^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -252,6 +256,9 @@ Fixed Point Support in Clang
252256
AST Matchers
253257
------------
254258

259+
- Fixed an issue with the `hasName` and `hasAnyName` matcher when matching
260+
inline namespaces with an enclosing namespace of the same name.
261+
255262
clang-format
256263
------------
257264

@@ -275,6 +282,10 @@ Crash and bug fixes
275282
Improvements
276283
^^^^^^^^^^^^
277284

285+
- Improved the handling of the ``ownership_returns`` attribute. Now, Clang reports an
286+
error if the attribute is attached to a function that returns a non-pointer value.
287+
Fixes (#GH99501)
288+
278289
Moved checkers
279290
^^^^^^^^^^^^^^
280291

clang/docs/analyzer/checkers.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,7 +1703,13 @@ are detected:
17031703
* Invalid 3rd ("``whence``") argument to ``fseek``.
17041704
17051705
The stream operations are by this checker usually split into two cases, a success
1706-
and a failure case. However, in the case of write operations (like ``fwrite``,
1706+
and a failure case.
1707+
On the success case it also assumes that the current value of ``stdout``,
1708+
``stderr``, or ``stdin`` can't be equal to the file pointer returned by ``fopen``.
1709+
Operations performed on ``stdout``, ``stderr``, or ``stdin`` are not checked by
1710+
this checker in contrast to the streams opened by ``fopen``.
1711+
1712+
In the case of write operations (like ``fwrite``,
17071713
``fprintf`` and even ``fsetpos``) this behavior could produce a large amount of
17081714
unwanted reports on projects that don't have error checks around the write
17091715
operations, so by default the checker assumes that write operations always succeed.
@@ -1769,9 +1775,7 @@ are assumed to succeed.)
17691775
**Limitations**
17701776
17711777
The checker does not track the correspondence between integer file descriptors
1772-
and ``FILE *`` pointers. Operations on standard streams like ``stdin`` are not
1773-
treated specially and are therefore often not recognized (because these streams
1774-
are usually not opened explicitly by the program, and are global variables).
1778+
and ``FILE *`` pointers.
17751779
17761780
.. _osx-checkers:
17771781

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3330,6 +3330,8 @@ def err_attribute_invalid_implicit_this_argument : Error<
33303330
"%0 attribute is invalid for the implicit this argument">;
33313331
def err_ownership_type : Error<
33323332
"%0 attribute only applies to %select{pointer|integer}1 arguments">;
3333+
def err_ownership_takes_return_type : Error<
3334+
"'ownership_returns' attribute only applies to functions that return a pointer">;
33333335
def err_ownership_returns_index_mismatch : Error<
33343336
"'ownership_returns' attribute index does not match; here it is %0">;
33353337
def note_ownership_returns_index_mismatch : Note<

clang/include/clang/Lex/Preprocessor.h

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,11 @@ class Preprocessor {
11601160
/// invoked (at which point the last position is popped).
11611161
std::vector<CachedTokensTy::size_type> BacktrackPositions;
11621162

1163+
/// Stack of cached tokens/initial number of cached tokens pairs, allowing
1164+
/// nested unannotated backtracks.
1165+
std::vector<std::pair<CachedTokensTy, CachedTokensTy::size_type>>
1166+
UnannotatedBacktrackTokens;
1167+
11631168
/// True if \p Preprocessor::SkipExcludedConditionalBlock() is running.
11641169
/// This is used to guard against calling this function recursively.
11651170
///
@@ -1722,8 +1727,16 @@ class Preprocessor {
17221727
/// at some point after EnableBacktrackAtThisPos. If you don't, caching of
17231728
/// tokens will continue indefinitely.
17241729
///
1725-
void EnableBacktrackAtThisPos();
1730+
/// \param Unannotated Whether token annotations are reverted upon calling
1731+
/// Backtrack().
1732+
void EnableBacktrackAtThisPos(bool Unannotated = false);
1733+
1734+
private:
1735+
std::pair<CachedTokensTy::size_type, bool> LastBacktrackPos();
1736+
1737+
CachedTokensTy PopUnannotatedBacktrackTokens();
17261738

1739+
public:
17271740
/// Disable the last EnableBacktrackAtThisPos call.
17281741
void CommitBacktrackedTokens();
17291742

@@ -1735,6 +1748,12 @@ class Preprocessor {
17351748
/// caching of tokens is on.
17361749
bool isBacktrackEnabled() const { return !BacktrackPositions.empty(); }
17371750

1751+
/// True if EnableBacktrackAtThisPos() was called and
1752+
/// caching of unannotated tokens is on.
1753+
bool isUnannotatedBacktrackEnabled() const {
1754+
return !UnannotatedBacktrackTokens.empty();
1755+
}
1756+
17381757
/// Lex the next token for this preprocessor.
17391758
void Lex(Token &Result);
17401759

@@ -1841,8 +1860,9 @@ class Preprocessor {
18411860
void RevertCachedTokens(unsigned N) {
18421861
assert(isBacktrackEnabled() &&
18431862
"Should only be called when tokens are cached for backtracking");
1844-
assert(signed(CachedLexPos) - signed(N) >= signed(BacktrackPositions.back())
1845-
&& "Should revert tokens up to the last backtrack position, not more");
1863+
assert(signed(CachedLexPos) - signed(N) >=
1864+
signed(LastBacktrackPos().first) &&
1865+
"Should revert tokens up to the last backtrack position, not more");
18461866
assert(signed(CachedLexPos) - signed(N) >= 0 &&
18471867
"Corrupted backtrack positions ?");
18481868
CachedLexPos -= N;

clang/include/clang/Parse/Parser.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,8 @@ class Parser : public CodeCompletionHandler {
10251025
/// ....
10261026
/// TPA.Revert();
10271027
///
1028+
/// If the Unannotated parameter is true, any token annotations created
1029+
/// during the tentative parse are reverted.
10281030
class TentativeParsingAction {
10291031
Parser &P;
10301032
PreferredTypeBuilder PrevPreferredType;
@@ -1034,15 +1036,15 @@ class Parser : public CodeCompletionHandler {
10341036
bool isActive;
10351037

10361038
public:
1037-
explicit TentativeParsingAction(Parser &p)
1039+
explicit TentativeParsingAction(Parser &p, bool Unannotated = false)
10381040
: P(p), PrevPreferredType(P.PreferredType) {
10391041
PrevTok = P.Tok;
10401042
PrevTentativelyDeclaredIdentifierCount =
10411043
P.TentativelyDeclaredIdentifiers.size();
10421044
PrevParenCount = P.ParenCount;
10431045
PrevBracketCount = P.BracketCount;
10441046
PrevBraceCount = P.BraceCount;
1045-
P.PP.EnableBacktrackAtThisPos();
1047+
P.PP.EnableBacktrackAtThisPos(Unannotated);
10461048
isActive = true;
10471049
}
10481050
void Commit() {
@@ -1073,13 +1075,11 @@ class Parser : public CodeCompletionHandler {
10731075
class RevertingTentativeParsingAction
10741076
: private Parser::TentativeParsingAction {
10751077
public:
1076-
RevertingTentativeParsingAction(Parser &P)
1077-
: Parser::TentativeParsingAction(P) {}
1078+
using TentativeParsingAction::TentativeParsingAction;
1079+
10781080
~RevertingTentativeParsingAction() { Revert(); }
10791081
};
10801082

1081-
class UnannotatedTentativeParsingAction;
1082-
10831083
/// ObjCDeclContextSwitch - An object used to switch context from
10841084
/// an objective-c decl context to its enclosing decl context and
10851085
/// back.
@@ -1984,7 +1984,8 @@ class Parser : public CodeCompletionHandler {
19841984
CXXScopeSpec &SS, ParsedType ObjectType, bool ObjectHasErrors,
19851985
bool EnteringContext, bool *MayBePseudoDestructor = nullptr,
19861986
bool IsTypename = false, const IdentifierInfo **LastII = nullptr,
1987-
bool OnlyNamespace = false, bool InUsingDeclaration = false);
1987+
bool OnlyNamespace = false, bool InUsingDeclaration = false,
1988+
bool Disambiguation = false);
19881989

19891990
//===--------------------------------------------------------------------===//
19901991
// C++11 5.1.2: Lambda expressions

clang/lib/ASTMatchers/ASTMatchersInternal.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -537,14 +537,23 @@ class PatternSet {
537537
/// that didn't match.
538538
/// Return true if there are still any patterns left.
539539
bool consumeNameSuffix(StringRef NodeName, bool CanSkip) {
540-
for (size_t I = 0; I < Patterns.size();) {
541-
if (::clang::ast_matchers::internal::consumeNameSuffix(Patterns[I].P,
542-
NodeName) ||
543-
CanSkip) {
544-
++I;
545-
} else {
546-
Patterns.erase(Patterns.begin() + I);
540+
if (CanSkip) {
541+
// If we can skip the node, then we need to handle the case where a
542+
// skipped node has the same name as its parent.
543+
// namespace a { inline namespace a { class A; } }
544+
// cxxRecordDecl(hasName("::a::A"))
545+
// To do this, any patterns that match should be duplicated in our set,
546+
// one of them with the tail removed.
547+
for (size_t I = 0, E = Patterns.size(); I != E; ++I) {
548+
StringRef Pattern = Patterns[I].P;
549+
if (ast_matchers::internal::consumeNameSuffix(Patterns[I].P, NodeName))
550+
Patterns.push_back({Pattern, Patterns[I].IsFullyQualified});
547551
}
552+
} else {
553+
llvm::erase_if(Patterns, [&NodeName](auto &Pattern) {
554+
return !::clang::ast_matchers::internal::consumeNameSuffix(Pattern.P,
555+
NodeName);
556+
});
548557
}
549558
return !Patterns.empty();
550559
}

clang/lib/CodeGen/CGGPUBuiltin.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -552,12 +552,3 @@ CodeGenFunction::EmitHostexecAllocAndExecFns(const CallExpr *E,
552552
hostexecVargsReturnsFnDeclaration(CGM, E->getType(), GPUStubFunctionName),
553553
{DataStructPtr, BufferLen}));
554554
}
555-
#if 0
556-
RValue CodeGenFunction::EmitOpenMPDevicePrintfCallExpr(const CallExpr *E) {
557-
assert(getTarget().getTriple().isNVPTX() ||
558-
getTarget().getTriple().isAMDGCN());
559-
// This will result in a NOP on AMDGPU, unimplimented.
560-
return EmitDevicePrintfCallExpr(E, this, GetOpenMPVprintfDeclaration(CGM),
561-
true);
562-
}
563-
#endif

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,12 +630,24 @@ void amdgpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
630630
Args.AddAllArgs(CmdArgs, options::OPT_L);
631631
getToolChain().AddFilePathLibArgs(Args, CmdArgs);
632632
AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
633-
if (C.getDriver().isUsingLTO())
633+
if (C.getDriver().isUsingLTO()) {
634634
addLTOOptions(getToolChain(), Args, CmdArgs, Output, Inputs[0],
635635
C.getDriver().getLTOMode() == LTOK_Thin);
636-
else if (Args.hasArg(options::OPT_mcpu_EQ))
636+
} else if (Args.hasArg(options::OPT_mcpu_EQ)) {
637637
CmdArgs.push_back(Args.MakeArgString(
638-
"-plugin-opt=mcpu=" + Args.getLastArgValue(options::OPT_mcpu_EQ)));
638+
"-plugin-opt=mcpu=" +
639+
getProcessorFromTargetID(getToolChain().getTriple(),
640+
Args.getLastArgValue(options::OPT_mcpu_EQ))));
641+
}
642+
643+
// Always pass the target-id features to the LTO job.
644+
std::vector<StringRef> Features;
645+
getAMDGPUTargetFeatures(C.getDriver(), getToolChain().getTriple(), Args,
646+
Features);
647+
if (!Features.empty()) {
648+
CmdArgs.push_back(
649+
Args.MakeArgString("-plugin-opt=-mattr=" + llvm::join(Features, ",")));
650+
}
639651

640652
addGPULibraries(getToolChain(), Args, CmdArgs);
641653

clang/lib/Lex/PPCaching.cpp

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
#include "clang/Lex/Preprocessor.h"
1515
using namespace clang;
1616

17+
std::pair<Preprocessor::CachedTokensTy::size_type, bool>
18+
Preprocessor::LastBacktrackPos() {
19+
assert(isBacktrackEnabled());
20+
auto BacktrackPos = BacktrackPositions.back();
21+
bool Unannotated =
22+
static_cast<CachedTokensTy::difference_type>(BacktrackPos) < 0;
23+
return {Unannotated ? ~BacktrackPos : BacktrackPos, Unannotated};
24+
}
25+
1726
// EnableBacktrackAtThisPos - From the point that this method is called, and
1827
// until CommitBacktrackedTokens() or Backtrack() is called, the Preprocessor
1928
// keeps track of the lexed tokens so that a subsequent Backtrack() call will
@@ -22,26 +31,45 @@ using namespace clang;
2231
// Nested backtracks are allowed, meaning that EnableBacktrackAtThisPos can
2332
// be called multiple times and CommitBacktrackedTokens/Backtrack calls will
2433
// be combined with the EnableBacktrackAtThisPos calls in reverse order.
25-
void Preprocessor::EnableBacktrackAtThisPos() {
34+
void Preprocessor::EnableBacktrackAtThisPos(bool Unannotated) {
2635
assert(LexLevel == 0 && "cannot use lookahead while lexing");
27-
BacktrackPositions.push_back(CachedLexPos);
36+
BacktrackPositions.push_back(Unannotated ? ~CachedLexPos : CachedLexPos);
37+
if (Unannotated)
38+
UnannotatedBacktrackTokens.emplace_back(CachedTokens, CachedTokens.size());
2839
EnterCachingLexMode();
2940
}
3041

42+
Preprocessor::CachedTokensTy Preprocessor::PopUnannotatedBacktrackTokens() {
43+
assert(isUnannotatedBacktrackEnabled() && "missing unannotated tokens?");
44+
auto [UnannotatedTokens, NumCachedToks] =
45+
std::move(UnannotatedBacktrackTokens.back());
46+
UnannotatedBacktrackTokens.pop_back();
47+
// If another unannotated backtrack is active, propagate any tokens that were
48+
// lexed (not cached) since EnableBacktrackAtThisPos was last called.
49+
if (isUnannotatedBacktrackEnabled())
50+
UnannotatedBacktrackTokens.back().first.append(
51+
UnannotatedTokens.begin() + NumCachedToks, UnannotatedTokens.end());
52+
return std::move(UnannotatedTokens);
53+
}
54+
3155
// Disable the last EnableBacktrackAtThisPos call.
3256
void Preprocessor::CommitBacktrackedTokens() {
33-
assert(!BacktrackPositions.empty()
34-
&& "EnableBacktrackAtThisPos was not called!");
57+
assert(isBacktrackEnabled() && "EnableBacktrackAtThisPos was not called!");
58+
auto [BacktrackPos, Unannotated] = LastBacktrackPos();
3559
BacktrackPositions.pop_back();
60+
if (Unannotated)
61+
PopUnannotatedBacktrackTokens();
3662
}
3763

3864
// Make Preprocessor re-lex the tokens that were lexed since
3965
// EnableBacktrackAtThisPos() was previously called.
4066
void Preprocessor::Backtrack() {
41-
assert(!BacktrackPositions.empty()
42-
&& "EnableBacktrackAtThisPos was not called!");
43-
CachedLexPos = BacktrackPositions.back();
67+
assert(isBacktrackEnabled() && "EnableBacktrackAtThisPos was not called!");
68+
auto [BacktrackPos, Unannotated] = LastBacktrackPos();
4469
BacktrackPositions.pop_back();
70+
CachedLexPos = BacktrackPos;
71+
if (Unannotated)
72+
CachedTokens = PopUnannotatedBacktrackTokens();
4573
recomputeCurLexerKind();
4674
}
4775

@@ -67,6 +95,8 @@ void Preprocessor::CachingLex(Token &Result) {
6795
EnterCachingLexModeUnchecked();
6896
CachedTokens.push_back(Result);
6997
++CachedLexPos;
98+
if (isUnannotatedBacktrackEnabled())
99+
UnannotatedBacktrackTokens.back().first.push_back(Result);
70100
return;
71101
}
72102

@@ -108,6 +138,8 @@ const Token &Preprocessor::PeekAhead(unsigned N) {
108138
for (size_t C = CachedLexPos + N - CachedTokens.size(); C > 0; --C) {
109139
CachedTokens.push_back(Token());
110140
Lex(CachedTokens.back());
141+
if (isUnannotatedBacktrackEnabled())
142+
UnannotatedBacktrackTokens.back().first.push_back(CachedTokens.back());
111143
}
112144
EnterCachingLexMode();
113145
return CachedTokens.back();
@@ -124,7 +156,7 @@ void Preprocessor::AnnotatePreviousCachedTokens(const Token &Tok) {
124156
for (CachedTokensTy::size_type i = CachedLexPos; i != 0; --i) {
125157
CachedTokensTy::iterator AnnotBegin = CachedTokens.begin() + i-1;
126158
if (AnnotBegin->getLocation() == Tok.getLocation()) {
127-
assert((BacktrackPositions.empty() || BacktrackPositions.back() <= i) &&
159+
assert((!isBacktrackEnabled() || LastBacktrackPos().first <= i) &&
128160
"The backtrack pos points inside the annotated tokens!");
129161
// Replace the cached tokens with the single annotation token.
130162
if (i < CachedLexPos)

clang/lib/Lex/Preprocessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Preprocessor::Preprocessor(std::shared_ptr<PreprocessorOptions> PPOpts,
170170
}
171171

172172
Preprocessor::~Preprocessor() {
173-
assert(BacktrackPositions.empty() && "EnableBacktrack/Backtrack imbalance!");
173+
assert(!isBacktrackEnabled() && "EnableBacktrack/Backtrack imbalance!");
174174

175175
IncludeMacroStack.clear();
176176

0 commit comments

Comments
 (0)