Skip to content

Commit 88ce203

Browse files
author
git apple-llvm automerger
committed
Merge commit '8c2c6af02ea7' from llvm.org/main into experimental/cas/main
2 parents f7c6db4 + 8c2c6af commit 88ce203

File tree

75 files changed

+1478
-877
lines changed

Some content is hidden

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

75 files changed

+1478
-877
lines changed

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void DWARFRewriter::updateDebugInfo() {
199199
std::make_unique<DebugLoclistWriter>(*CU.get(), DwarfVersion, false);
200200

201201
if (std::optional<uint64_t> DWOId = CU->getDWOId()) {
202-
assert(LocListWritersByCU.count(*DWOId) == 0 &&
202+
assert(RangeListsWritersByCU.count(*DWOId) == 0 &&
203203
"RangeLists writer for DWO unit already exists.");
204204
auto RangeListsSectionWriter =
205205
std::make_unique<DebugRangeListsSectionWriter>();

clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ void AssertSideEffectCheck::check(const MatchFinder::MatchResult &Result) {
117117
StringRef AssertMacroName;
118118
while (Loc.isValid() && Loc.isMacroID()) {
119119
StringRef MacroName = Lexer::getImmediateMacroName(Loc, SM, LangOpts);
120+
Loc = SM.getImmediateMacroCallerLoc(Loc);
120121

121122
// Check if this macro is an assert.
122123
if (llvm::is_contained(AssertMacros, MacroName)) {
123124
AssertMacroName = MacroName;
124125
break;
125126
}
126-
Loc = SM.getImmediateMacroCallerLoc(Loc);
127127
}
128128
if (AssertMacroName.empty())
129129
return;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#pragma clang system_header
2+
3+
int abort();
4+
5+
#ifdef NDEBUG
6+
#define assert(x) 1
7+
#else
8+
#define assert(x) \
9+
if (!(x)) \
10+
(void)abort()
11+
#endif
12+
13+
void print(...);
14+
#define assert2(e) (__builtin_expect(!(e), 0) ? \
15+
print (#e, __FILE__, __LINE__) : (void)0)
16+
17+
#ifdef NDEBUG
18+
#define my_assert(x) 1
19+
#else
20+
#define my_assert(x) \
21+
((void)((x) ? 1 : abort()))
22+
#endif
23+
24+
#ifdef NDEBUG
25+
#define not_my_assert(x) 1
26+
#else
27+
#define not_my_assert(x) \
28+
if (!(x)) \
29+
(void)abort()
30+
#endif
31+
32+
#define real_assert(x) ((void)((x) ? 1 : abort()))
33+
#define wrap1(x) real_assert(x)
34+
#define wrap2(x) wrap1(x)
35+
#define convoluted_assert(x) wrap2(x)
36+
37+
#define msvc_assert(expression) (void)( \
38+
(!!(expression)) || \
39+
(abort(), 0) \
40+
)

clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,5 @@
1-
// RUN: %check_clang_tidy %s bugprone-assert-side-effect %t -- -config="{CheckOptions: [{key: bugprone-assert-side-effect.CheckFunctionCalls, value: true}, {key: bugprone-assert-side-effect.AssertMacros, value: 'assert,assert2,my_assert,convoluted_assert,msvc_assert'}, {key: bugprone-assert-side-effect.IgnoredFunctions, value: 'MyClass::badButIgnoredFunc'}]}" -- -fexceptions
2-
3-
//===--- assert definition block ------------------------------------------===//
4-
int abort() { return 0; }
5-
6-
#ifdef NDEBUG
7-
#define assert(x) 1
8-
#else
9-
#define assert(x) \
10-
if (!(x)) \
11-
(void)abort()
12-
#endif
13-
14-
void print(...);
15-
#define assert2(e) (__builtin_expect(!(e), 0) ? \
16-
print (#e, __FILE__, __LINE__) : (void)0)
17-
18-
#ifdef NDEBUG
19-
#define my_assert(x) 1
20-
#else
21-
#define my_assert(x) \
22-
((void)((x) ? 1 : abort()))
23-
#endif
24-
25-
#ifdef NDEBUG
26-
#define not_my_assert(x) 1
27-
#else
28-
#define not_my_assert(x) \
29-
if (!(x)) \
30-
(void)abort()
31-
#endif
32-
33-
#define real_assert(x) ((void)((x) ? 1 : abort()))
34-
#define wrap1(x) real_assert(x)
35-
#define wrap2(x) wrap1(x)
36-
#define convoluted_assert(x) wrap2(x)
37-
38-
#define msvc_assert(expression) (void)( \
39-
(!!(expression)) || \
40-
(abort(), 0) \
41-
)
42-
43-
44-
//===----------------------------------------------------------------------===//
1+
// RUN: %check_clang_tidy %s bugprone-assert-side-effect %t -- -config="{CheckOptions: [{key: bugprone-assert-side-effect.CheckFunctionCalls, value: true}, {key: bugprone-assert-side-effect.AssertMacros, value: 'assert,assert2,my_assert,convoluted_assert,msvc_assert'}, {key: bugprone-assert-side-effect.IgnoredFunctions, value: 'MyClass::badButIgnoredFunc'}]}" -- -fexceptions -I %S/Inputs/assert-side-effect
2+
#include <assert.h>
453

464
bool badButIgnoredFunc(int a, int b) { return a * b > 0; }
475

clang/include/clang/AST/DeclBase.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,12 @@ class alignas(8) Decl {
11721172
}
11731173
}
11741174

1175+
/// Clears the namespace of this declaration.
1176+
///
1177+
/// This is useful if we want this declaration to be available for
1178+
/// redeclaration lookup but otherwise hidden for ordinary name lookups.
1179+
void clearIdentifierNamespace() { IdentifierNamespace = 0; }
1180+
11751181
enum FriendObjectKind {
11761182
FOK_None, ///< Not a friend object.
11771183
FOK_Declared, ///< A friend of a previously-declared entity.

clang/include/clang/AST/DeclTemplate.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,9 +2309,15 @@ class ClassTemplateDecl : public RedeclarableTemplateDecl {
23092309
return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
23102310
}
23112311

2312+
void setCommonPtr(Common *C) {
2313+
RedeclarableTemplateDecl::Common = C;
2314+
}
2315+
23122316
public:
2317+
23132318
friend class ASTDeclReader;
23142319
friend class ASTDeclWriter;
2320+
friend class TemplateDeclInstantiator;
23152321

23162322
/// Load any lazily-loaded specializations from the external source.
23172323
void LoadLazySpecializations() const;

clang/include/clang/Lex/Pragma.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ class PragmaNamespace : public PragmaHandler {
123123
PragmaNamespace *getIfNamespace() override { return this; }
124124
};
125125

126+
/// Destringize a \c _Pragma("") string according to C11 6.10.9.1:
127+
/// "The string literal is destringized by deleting any encoding prefix,
128+
/// deleting the leading and trailing double-quotes, replacing each escape
129+
/// sequence \" by a double-quote, and replacing each escape sequence \\ by a
130+
/// single backslash."
131+
void prepare_PragmaString(SmallVectorImpl<char> &StrVal);
132+
126133
} // namespace clang
127134

128135
#endif // LLVM_CLANG_LEX_PRAGMA_H

clang/include/clang/Sema/Template.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,21 @@ enum class TemplateSubstitutionKind : char {
232232
/// Replaces the current 'innermost' level with the provided argument list.
233233
/// This is useful for type deduction cases where we need to get the entire
234234
/// list from the AST, but then add the deduced innermost list.
235-
void replaceInnermostTemplateArguments(ArgList Args) {
236-
assert(TemplateArgumentLists.size() > 0 && "Replacing in an empty list?");
237-
TemplateArgumentLists[0].Args = Args;
235+
void replaceInnermostTemplateArguments(Decl *AssociatedDecl, ArgList Args) {
236+
assert((!TemplateArgumentLists.empty() || NumRetainedOuterLevels) &&
237+
"Replacing in an empty list?");
238+
239+
if (!TemplateArgumentLists.empty()) {
240+
assert((TemplateArgumentLists[0].AssociatedDeclAndFinal.getPointer() ||
241+
TemplateArgumentLists[0].AssociatedDeclAndFinal.getPointer() ==
242+
AssociatedDecl) &&
243+
"Trying to change incorrect declaration?");
244+
TemplateArgumentLists[0].Args = Args;
245+
} else {
246+
--NumRetainedOuterLevels;
247+
TemplateArgumentLists.push_back(
248+
{{AssociatedDecl, /*Final=*/false}, Args});
249+
}
238250
}
239251

240252
/// Add an outermost level that we are not substituting. We have no

clang/lib/Lex/DependencyDirectivesScanner.cpp

Lines changed: 105 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "clang/Basic/Diagnostic.h"
2020
#include "clang/Lex/LexDiagnostic.h"
2121
#include "clang/Lex/Lexer.h"
22+
#include "clang/Lex/Pragma.h"
2223
#include "llvm/ADT/ScopeExit.h"
2324
#include "llvm/ADT/SmallString.h"
2425
#include "llvm/ADT/StringMap.h"
@@ -72,6 +73,8 @@ struct Scanner {
7273
// Set the lexer to use 'tok::at' for '@', instead of 'tok::unknown'.
7374
LangOpts.ObjC = true;
7475
LangOpts.LineComment = true;
76+
// FIXME: we do not enable C11 or C++11, so we are missing u/u8/U"" and
77+
// R"()" literals.
7578
return LangOpts;
7679
}
7780

@@ -91,6 +94,10 @@ struct Scanner {
9194
void skipLine(const char *&First, const char *const End);
9295
void skipDirective(StringRef Name, const char *&First, const char *const End);
9396

97+
/// Returns the spelling of a string literal or identifier after performing
98+
/// any processing needed to handle \c clang::Token::NeedsCleaning.
99+
StringRef cleanStringIfNeeded(const dependency_directives_scan::Token &Tok);
100+
94101
/// Lexes next token and if it is identifier returns its string, otherwise
95102
/// it skips the current line and returns \p std::nullopt.
96103
///
@@ -112,13 +119,30 @@ struct Scanner {
112119
const char *&First,
113120
const char *const End);
114121

122+
/// Lexes next token and returns true iff it matches the kind \p K.
123+
/// Otherwise it skips the current line and returns false.
124+
///
125+
/// In any case (whatever the token kind) \p First and the \p Lexer will
126+
/// advance beyond the token.
127+
[[nodiscard]] bool isNextTokenOrSkipLine(tok::TokenKind K, const char *&First,
128+
const char *const End);
129+
130+
/// Lexes next token and if it is string literal, returns its string.
131+
/// Otherwise, it skips the current line and returns \p std::nullopt.
132+
///
133+
/// In any case (whatever the token kind) \p First and the \p Lexer will
134+
/// advance beyond the token.
135+
[[nodiscard]] std::optional<StringRef>
136+
tryLexStringLiteralOrSkipLine(const char *&First, const char *const End);
137+
115138
[[nodiscard]] bool scanImpl(const char *First, const char *const End);
116139
[[nodiscard]] bool lexPPLine(const char *&First, const char *const End);
117140
[[nodiscard]] bool lexAt(const char *&First, const char *const End);
118141
[[nodiscard]] bool lexModule(const char *&First, const char *const End);
119142
[[nodiscard]] bool lexDefine(const char *HashLoc, const char *&First,
120143
const char *const End);
121144
[[nodiscard]] bool lexPragma(const char *&First, const char *const End);
145+
[[nodiscard]] bool lex_Pragma(const char *&First, const char *const End);
122146
[[nodiscard]] bool lexEndif(const char *&First, const char *const End);
123147
[[nodiscard]] bool lexDefault(DirectiveKind Kind, const char *&First,
124148
const char *const End);
@@ -525,22 +549,18 @@ void Scanner::lexPPDirectiveBody(const char *&First, const char *const End) {
525549
}
526550
}
527551

528-
[[nodiscard]] std::optional<StringRef>
529-
Scanner::tryLexIdentifierOrSkipLine(const char *&First, const char *const End) {
530-
const dependency_directives_scan::Token &Tok = lexToken(First, End);
531-
if (Tok.isNot(tok::raw_identifier)) {
532-
if (!Tok.is(tok::eod))
533-
skipLine(First, End);
534-
return std::nullopt;
535-
}
536-
552+
StringRef
553+
Scanner::cleanStringIfNeeded(const dependency_directives_scan::Token &Tok) {
537554
bool NeedsCleaning = Tok.Flags & clang::Token::NeedsCleaning;
538555
if (LLVM_LIKELY(!NeedsCleaning))
539556
return Input.slice(Tok.Offset, Tok.getEnd());
540557

541558
SmallString<64> Spelling;
542559
Spelling.resize(Tok.Length);
543560

561+
// FIXME: C++11 raw string literals need special handling (see getSpellingSlow
562+
// in the Lexer). Currently we cannot see them due to our LangOpts.
563+
544564
unsigned SpellingLength = 0;
545565
const char *BufPtr = Input.begin() + Tok.Offset;
546566
const char *AfterIdent = Input.begin() + Tok.getEnd();
@@ -555,6 +575,18 @@ Scanner::tryLexIdentifierOrSkipLine(const char *&First, const char *const End) {
555575
.first->first();
556576
}
557577

578+
std::optional<StringRef>
579+
Scanner::tryLexIdentifierOrSkipLine(const char *&First, const char *const End) {
580+
const dependency_directives_scan::Token &Tok = lexToken(First, End);
581+
if (Tok.isNot(tok::raw_identifier)) {
582+
if (!Tok.is(tok::eod))
583+
skipLine(First, End);
584+
return std::nullopt;
585+
}
586+
587+
return cleanStringIfNeeded(Tok);
588+
}
589+
558590
StringRef Scanner::lexIdentifier(const char *&First, const char *const End) {
559591
std::optional<StringRef> Id = tryLexIdentifierOrSkipLine(First, End);
560592
assert(Id && "expected identifier token");
@@ -572,6 +604,28 @@ bool Scanner::isNextIdentifierOrSkipLine(StringRef Id, const char *&First,
572604
return false;
573605
}
574606

607+
bool Scanner::isNextTokenOrSkipLine(tok::TokenKind K, const char *&First,
608+
const char *const End) {
609+
const dependency_directives_scan::Token &Tok = lexToken(First, End);
610+
if (Tok.is(K))
611+
return true;
612+
skipLine(First, End);
613+
return false;
614+
}
615+
616+
std::optional<StringRef>
617+
Scanner::tryLexStringLiteralOrSkipLine(const char *&First,
618+
const char *const End) {
619+
const dependency_directives_scan::Token &Tok = lexToken(First, End);
620+
if (!tok::isStringLiteral(Tok.Kind)) {
621+
if (!Tok.is(tok::eod))
622+
skipLine(First, End);
623+
return std::nullopt;
624+
}
625+
626+
return cleanStringIfNeeded(Tok);
627+
}
628+
575629
bool Scanner::lexAt(const char *&First, const char *const End) {
576630
// Handle "@import".
577631

@@ -629,6 +683,41 @@ bool Scanner::lexModule(const char *&First, const char *const End) {
629683
return lexModuleDirectiveBody(Kind, First, End);
630684
}
631685

686+
bool Scanner::lex_Pragma(const char *&First, const char *const End) {
687+
if (!isNextTokenOrSkipLine(tok::l_paren, First, End))
688+
return false;
689+
690+
std::optional<StringRef> Str = tryLexStringLiteralOrSkipLine(First, End);
691+
692+
if (!Str || !isNextTokenOrSkipLine(tok::r_paren, First, End))
693+
return false;
694+
695+
SmallString<64> Buffer(*Str);
696+
prepare_PragmaString(Buffer);
697+
698+
// Use a new scanner instance since the tokens will be inside the allocated
699+
// string. We should already have captured all the relevant tokens in the
700+
// current scanner.
701+
SmallVector<dependency_directives_scan::Token> DiscardTokens;
702+
const char *Begin = Buffer.c_str();
703+
Scanner PragmaScanner{StringRef(Begin, Buffer.size()), DiscardTokens, Diags,
704+
InputSourceLoc};
705+
706+
PragmaScanner.TheLexer.setParsingPreprocessorDirective(true);
707+
if (PragmaScanner.lexPragma(Begin, Buffer.end()))
708+
return true;
709+
710+
DirectiveKind K = PragmaScanner.topDirective();
711+
if (K == pp_none) {
712+
skipLine(First, End);
713+
return false;
714+
}
715+
716+
assert(Begin == Buffer.end());
717+
pushDirective(K);
718+
return false;
719+
}
720+
632721
bool Scanner::lexPragma(const char *&First, const char *const End) {
633722
std::optional<StringRef> FoundId = tryLexIdentifierOrSkipLine(First, End);
634723
if (!FoundId)
@@ -713,6 +802,7 @@ static bool isStartOfRelevantLine(char First) {
713802
case 'i':
714803
case 'e':
715804
case 'm':
805+
case '_':
716806
return true;
717807
}
718808
return false;
@@ -749,6 +839,12 @@ bool Scanner::lexPPLine(const char *&First, const char *const End) {
749839
if (*First == 'i' || *First == 'e' || *First == 'm')
750840
return lexModule(First, End);
751841

842+
if (*First == '_') {
843+
if (isNextIdentifierOrSkipLine("_Pragma", First, End))
844+
return lex_Pragma(First, End);
845+
return false;
846+
}
847+
752848
// Handle preprocessing directives.
753849

754850
TheLexer.setParsingPreprocessorDirective(true);

0 commit comments

Comments
 (0)