Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//===--- ReturnConstRefFromParameterCheck.h - clang-tidy --------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RETURNCONSTREFFROMPARAMETERCHECK_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RETURNCONSTREFFROMPARAMETERCHECK_H

#include "../ClangTidyCheck.h"

namespace clang::tidy::bugprone {

/// Detects return statements that return a constant reference parameter as
/// constant reference. This may cause use-after-free errors if the caller uses
/// xvalues as arguments.
///
/// For the user-facing documentation see:
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/return-const-ref-from-parameter.html
class ReturnConstRefFromParameterCheck : public ClangTidyCheck {
public:
ReturnConstRefFromParameterCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
std::optional<TraversalKind> getCheckTraversalKind() const override {
// Use 'AsIs' to make sure the return type is exactly the same as the
// parameter type.
return TK_AsIs;
}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
};

} // namespace clang::tidy::bugprone

#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RETURNCONSTREFFROMPARAMETERCHECK_H
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer(
if (!F->hasInClassInitializer() &&
utils::type_traits::isTriviallyDefaultConstructible(F->getType(),
Context) &&
!isEmpty(Context, F->getType()) && !F->isUnnamedBitfield() &&
!isEmpty(Context, F->getType()) && !F->isUnnamedBitField() &&
!AnyMemberHasInitPerUnion)
FieldsToInit.insert(F);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ getAllNamedFields(const CXXRecordDecl *Record) {
std::set<const FieldDecl *> Result;
for (const auto *Field : Record->fields()) {
// Static data members are not in this range.
if (Field->isUnnamedBitfield())
if (Field->isUnnamedBitField())
continue;
Result.insert(Field);
}
Expand Down
103 changes: 89 additions & 14 deletions clang-tools-extra/clang-tidy/modernize/UseStartsEndsWithCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ void UseStartsEndsWithCheck::registerMatchers(MatchFinder *Finder) {
callee(cxxMethodDecl(hasName("find")).bind("find_fun")),
// ... on a class with a starts_with function.
on(hasType(
hasCanonicalType(hasDeclaration(ClassWithStartsWithFunction)))));
hasCanonicalType(hasDeclaration(ClassWithStartsWithFunction)))),
// Bind search expression.
hasArgument(0, expr().bind("search_expr")));

const auto RFindExpr = cxxMemberCallExpr(
// A method call with a second argument of zero...
Expand All @@ -52,15 +54,68 @@ void UseStartsEndsWithCheck::registerMatchers(MatchFinder *Finder) {
callee(cxxMethodDecl(hasName("rfind")).bind("find_fun")),
// ... on a class with a starts_with function.
on(hasType(
hasCanonicalType(hasDeclaration(ClassWithStartsWithFunction)))));
hasCanonicalType(hasDeclaration(ClassWithStartsWithFunction)))),
// Bind search expression.
hasArgument(0, expr().bind("search_expr")));

// Match a string literal and an integer or strlen() call matching the length.
const auto HasStringLiteralAndLengthArgs = [](const auto StringArgIndex,
const auto LengthArgIndex) {
return allOf(
hasArgument(StringArgIndex, stringLiteral().bind("string_literal_arg")),
hasArgument(LengthArgIndex,
anyOf(integerLiteral().bind("integer_literal_size_arg"),
callExpr(callee(functionDecl(parameterCountIs(1),
hasName("strlen"))),
hasArgument(0, stringLiteral().bind(
"strlen_arg"))))));
};

// Match a string variable and a call to length() or size().
const auto HasStringVariableAndSizeCallArgs = [](const auto StringArgIndex,
const auto LengthArgIndex) {
return allOf(
hasArgument(StringArgIndex, declRefExpr(hasDeclaration(
decl().bind("string_var_decl")))),
hasArgument(LengthArgIndex,
cxxMemberCallExpr(
callee(cxxMethodDecl(isConst(), parameterCountIs(0),
hasAnyName("size", "length"))),
on(declRefExpr(
to(decl(equalsBoundNode("string_var_decl"))))))));
};

const auto FindOrRFindExpr =
cxxMemberCallExpr(anyOf(FindExpr, RFindExpr)).bind("find_expr");
// Match either one of the two cases above.
const auto HasStringAndLengthArgs =
[HasStringLiteralAndLengthArgs, HasStringVariableAndSizeCallArgs](
const auto StringArgIndex, const auto LengthArgIndex) {
return anyOf(
HasStringLiteralAndLengthArgs(StringArgIndex, LengthArgIndex),
HasStringVariableAndSizeCallArgs(StringArgIndex, LengthArgIndex));
};

const auto CompareExpr = cxxMemberCallExpr(
// A method call with three arguments...
argumentCountIs(3),
// ... where the first argument is zero...
hasArgument(0, ZeroLiteral),
// ... named compare...
callee(cxxMethodDecl(hasName("compare")).bind("find_fun")),
// ... on a class with a starts_with function...
on(hasType(
hasCanonicalType(hasDeclaration(ClassWithStartsWithFunction)))),
// ... where the third argument is some string and the second a length.
HasStringAndLengthArgs(2, 1),
// Bind search expression.
hasArgument(2, expr().bind("search_expr")));

Finder->addMatcher(
// Match [=!]= with a zero on one side and a string.(r?)find on the other.
binaryOperator(hasAnyOperatorName("==", "!="),
hasOperands(FindOrRFindExpr, ZeroLiteral))
// Match [=!]= with a zero on one side and (r?)find|compare on the other.
binaryOperator(
hasAnyOperatorName("==", "!="),
hasOperands(cxxMemberCallExpr(anyOf(FindExpr, RFindExpr, CompareExpr))
.bind("find_expr"),
ZeroLiteral))
.bind("expr"),
this);
}
Expand All @@ -69,23 +124,42 @@ void UseStartsEndsWithCheck::check(const MatchFinder::MatchResult &Result) {
const auto *ComparisonExpr = Result.Nodes.getNodeAs<BinaryOperator>("expr");
const auto *FindExpr = Result.Nodes.getNodeAs<CXXMemberCallExpr>("find_expr");
const auto *FindFun = Result.Nodes.getNodeAs<CXXMethodDecl>("find_fun");
const auto *SearchExpr = Result.Nodes.getNodeAs<Expr>("search_expr");
const auto *StartsWithFunction =
Result.Nodes.getNodeAs<CXXMethodDecl>("starts_with_fun");

const auto *StringLiteralArg =
Result.Nodes.getNodeAs<StringLiteral>("string_literal_arg");
const auto *IntegerLiteralSizeArg =
Result.Nodes.getNodeAs<IntegerLiteral>("integer_literal_size_arg");
const auto *StrlenArg = Result.Nodes.getNodeAs<StringLiteral>("strlen_arg");

// Filter out compare cases where the length does not match string literal.
if (StringLiteralArg && IntegerLiteralSizeArg &&
StringLiteralArg->getLength() !=
IntegerLiteralSizeArg->getValue().getZExtValue()) {
return;
}

if (StringLiteralArg && StrlenArg &&
StringLiteralArg->getLength() != StrlenArg->getLength()) {
return;
}

if (ComparisonExpr->getBeginLoc().isMacroID()) {
return;
}

const bool Neg = ComparisonExpr->getOpcode() == BO_NE;

auto Diagnostic =
diag(FindExpr->getBeginLoc(), "use %0 instead of %1() %select{==|!=}2 0")
diag(FindExpr->getExprLoc(), "use %0 instead of %1() %select{==|!=}2 0")
<< StartsWithFunction->getName() << FindFun->getName() << Neg;

// Remove possible zero second argument and ' [!=]= 0' suffix.
// Remove possible arguments after search expression and ' [!=]= 0' suffix.
Diagnostic << FixItHint::CreateReplacement(
CharSourceRange::getTokenRange(
Lexer::getLocForEndOfToken(FindExpr->getArg(0)->getEndLoc(), 0,
Lexer::getLocForEndOfToken(SearchExpr->getEndLoc(), 0,
*Result.SourceManager, getLangOpts()),
ComparisonExpr->getEndLoc()),
")");
Expand All @@ -94,11 +168,12 @@ void UseStartsEndsWithCheck::check(const MatchFinder::MatchResult &Result) {
Diagnostic << FixItHint::CreateRemoval(CharSourceRange::getCharRange(
ComparisonExpr->getBeginLoc(), FindExpr->getBeginLoc()));

// Replace '(r?)find' with 'starts_with'.
// Replace method name by 'starts_with'.
// Remove possible arguments before search expression.
Diagnostic << FixItHint::CreateReplacement(
CharSourceRange::getTokenRange(FindExpr->getExprLoc(),
FindExpr->getExprLoc()),
StartsWithFunction->getName());
CharSourceRange::getCharRange(FindExpr->getExprLoc(),
SearchExpr->getBeginLoc()),
(StartsWithFunction->getName() + "(").str());

// Add possible negation '!'.
if (Neg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

namespace clang::tidy::modernize {

/// Checks whether a ``find`` or ``rfind`` result is compared with 0 and
/// suggests replacing with ``starts_with`` when the method exists in the class.
/// Notably, this will work with ``std::string`` and ``std::string_view``.
/// Checks for common roundabout ways to express ``starts_with`` and
/// ``ends_with`` and suggests replacing with ``starts_with`` when the method is
/// available. Notably, this will work with ``std::string`` and
/// ``std::string_view``.
///
/// For the user-facing documentation see:
/// http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-starts-ends-with.html
Expand Down
57 changes: 16 additions & 41 deletions clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,52 +454,27 @@ static constexpr StringLiteral VerifyConfigWarningEnd = " [-verify-config]\n";

static bool verifyChecks(const StringSet<> &AllChecks, StringRef CheckGlob,
StringRef Source) {
llvm::StringRef Cur, Rest;
GlobList Globs(CheckGlob);
bool AnyInvalid = false;
for (std::tie(Cur, Rest) = CheckGlob.split(',');
!(Cur.empty() && Rest.empty()); std::tie(Cur, Rest) = Rest.split(',')) {
Cur = Cur.trim();
if (Cur.empty())
for (const auto &Item : Globs.getItems()) {
if (Item.Text.starts_with("clang-diagnostic"))
continue;
Cur.consume_front("-");
if (Cur.starts_with("clang-diagnostic"))
continue;
if (Cur.contains('*')) {
SmallString<128> RegexText("^");
StringRef MetaChars("()^$|*+?.[]\\{}");
for (char C : Cur) {
if (C == '*')
RegexText.push_back('.');
else if (MetaChars.contains(C))
RegexText.push_back('\\');
RegexText.push_back(C);
}
RegexText.push_back('$');
llvm::Regex Glob(RegexText);
std::string Error;
if (!Glob.isValid(Error)) {
AnyInvalid = true;
llvm::WithColor::error(llvm::errs(), Source)
<< "building check glob '" << Cur << "' " << Error << "'\n";
continue;
}
if (llvm::none_of(AllChecks.keys(),
[&Glob](StringRef S) { return Glob.match(S); })) {
AnyInvalid = true;
if (llvm::none_of(AllChecks.keys(),
[&Item](StringRef S) { return Item.Regex.match(S); })) {
AnyInvalid = true;
if (Item.Text.contains('*'))
llvm::WithColor::warning(llvm::errs(), Source)
<< "check glob '" << Cur << "' doesn't match any known check"
<< "check glob '" << Item.Text << "' doesn't match any known check"
<< VerifyConfigWarningEnd;
else {
llvm::raw_ostream &Output =
llvm::WithColor::warning(llvm::errs(), Source)
<< "unknown check '" << Item.Text << '\'';
llvm::StringRef Closest = closest(Item.Text, AllChecks);
if (!Closest.empty())
Output << "; did you mean '" << Closest << '\'';
Output << VerifyConfigWarningEnd;
}
} else {
if (AllChecks.contains(Cur))
continue;
AnyInvalid = true;
llvm::raw_ostream &Output = llvm::WithColor::warning(llvm::errs(), Source)
<< "unknown check '" << Cur << '\'';
llvm::StringRef Closest = closest(Cur, AllChecks);
if (!Closest.empty())
Output << "; did you mean '" << Closest << '\'';
Output << VerifyConfigWarningEnd;
}
}
return AnyInvalid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ ExceptionSpecAnalyzer::analyzeRecord(const CXXRecordDecl *RecordDecl,
}

for (const auto *FDecl : RecordDecl->fields())
if (!FDecl->isInvalidDecl() && !FDecl->isUnnamedBitfield()) {
if (!FDecl->isInvalidDecl() && !FDecl->isUnnamedBitField()) {
State Result = analyzeFieldDecl(FDecl, Kind);
if (Result == State::Throwing || Result == State::Unknown)
return Result;
Expand Down
8 changes: 7 additions & 1 deletion clang-tools-extra/clangd/ClangdServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "refactor/Rename.h"
#include "refactor/Tweak.h"
#include "support/Cancellation.h"
#include "support/Context.h"
#include "support/Logger.h"
#include "support/MemoryTree.h"
#include "support/ThreadsafeFS.h"
Expand Down Expand Up @@ -112,7 +113,12 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
// Index outlives TUScheduler (declared first)
FIndex(FIndex),
// shared_ptr extends lifetime
Stdlib(Stdlib)]() mutable {
Stdlib(Stdlib),
// We have some FS implementations that rely on information in
// the context.
Ctx(Context::current().clone())]() mutable {
// Make sure we install the context into current thread.
WithContext C(std::move(Ctx));
clang::noteBottomOfStack();
IndexFileIn IF;
IF.Symbols = indexStandardLibrary(std::move(CI), Loc, *TFS);
Expand Down
7 changes: 7 additions & 0 deletions clang-tools-extra/clangd/Preamble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
Result->Marks = CapturedInfo.takeMarks();
Result->StatCache = StatCache;
Result->MainIsIncludeGuarded = CapturedInfo.isMainFileIncludeGuarded();
Result->TargetOpts = CI.TargetOpts;
if (PreambleCallback) {
trace::Span Tracer("Running PreambleCallback");
auto Ctx = CapturedInfo.takeLife();
Expand Down Expand Up @@ -913,6 +914,12 @@ PreamblePatch PreamblePatch::createMacroPatch(llvm::StringRef FileName,
}

void PreamblePatch::apply(CompilerInvocation &CI) const {
// Make sure the compilation uses same target opts as the preamble. Clang has
// no guarantees around using arbitrary options when reusing PCHs, and
// different target opts can result in crashes, see
// ParsedASTTest.PreambleWithDifferentTarget.
CI.TargetOpts = Baseline->TargetOpts;

// No need to map an empty file.
if (PatchContents.empty())
return;
Expand Down
5 changes: 5 additions & 0 deletions clang-tools-extra/clangd/Preamble.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "clang-include-cleaner/Record.h"
#include "support/Path.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetOptions.h"
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Frontend/PrecompiledPreamble.h"
#include "clang/Lex/Lexer.h"
Expand Down Expand Up @@ -97,6 +98,10 @@ struct PreambleData {
// Version of the ParseInputs this preamble was built from.
std::string Version;
tooling::CompileCommand CompileCommand;
// Target options used when building the preamble. Changes in target can cause
// crashes when deserializing preamble, this enables consumers to use the
// same target (without reparsing CompileCommand).
std::shared_ptr<TargetOptions> TargetOpts = nullptr;
PrecompiledPreamble Preamble;
std::vector<Diag> Diags;
// Processes like code completions and go-to-definitions will need #include
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(LLVM_LINK_COMPONENTS
support
AllTargetsInfos
FrontendOpenMP
TargetParser
)

if(CLANG_BUILT_STANDALONE)
Expand Down
25 changes: 25 additions & 0 deletions clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4160,7 +4160,32 @@ TEST(CompletionTest, DoNotCrash) {
auto Completions = completions(Case);
}
}
TEST(CompletionTest, PreambleFromDifferentTarget) {
constexpr std::string_view PreambleTarget = "x86_64";
constexpr std::string_view Contents =
"int foo(int); int num; int num2 = foo(n^";

Annotations Test(Contents);
auto TU = TestTU::withCode(Test.code());
TU.ExtraArgs.emplace_back("-target");
TU.ExtraArgs.emplace_back(PreambleTarget);
auto Preamble = TU.preamble();
ASSERT_TRUE(Preamble);
// Switch target to wasm.
TU.ExtraArgs.pop_back();
TU.ExtraArgs.emplace_back("wasm32");

MockFS FS;
auto Inputs = TU.inputs(FS);
auto Result = codeComplete(testPath(TU.Filename), Test.point(),
Preamble.get(), Inputs, {});
auto Signatures =
signatureHelp(testPath(TU.Filename), Test.point(), *Preamble, Inputs, {});

// Make sure we don't crash.
EXPECT_THAT(Result.Completions, Not(testing::IsEmpty()));
EXPECT_THAT(Signatures.signatures, Not(testing::IsEmpty()));
}
} // namespace
} // namespace clangd
} // namespace clang
14 changes: 7 additions & 7 deletions clang-tools-extra/clangd/unittests/FindTargetTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ TEST_F(TargetDeclTest, Types) {
[[auto]] X = S{};
)cpp";
// FIXME: deduced type missing in AST. https://llvm.org/PR42914
EXPECT_DECLS("AutoTypeLoc");
EXPECT_DECLS("AutoTypeLoc", );

Code = R"cpp(
template <typename... E>
Expand Down Expand Up @@ -727,13 +727,13 @@ TEST_F(TargetDeclTest, BuiltinTemplates) {
template <class T, int N>
using make_integer_sequence = [[__make_integer_seq]]<integer_sequence, T, N>;
)cpp";
EXPECT_DECLS("TemplateSpecializationTypeLoc");
EXPECT_DECLS("TemplateSpecializationTypeLoc", );

Code = R"cpp(
template <int N, class... Pack>
using type_pack_element = [[__type_pack_element]]<N, Pack...>;
)cpp";
EXPECT_DECLS("TemplateSpecializationTypeLoc");
EXPECT_DECLS("TemplateSpecializationTypeLoc", );
}

TEST_F(TargetDeclTest, MemberOfTemplate) {
Expand Down Expand Up @@ -1018,7 +1018,7 @@ TEST_F(TargetDeclTest, DependentTypes) {
typedef typename waldo<N - 1>::type::[[next]] type;
};
)cpp";
EXPECT_DECLS("DependentNameTypeLoc");
EXPECT_DECLS("DependentNameTypeLoc", );

// Similar to above but using mutually recursive templates.
Code = R"cpp(
Expand All @@ -1035,7 +1035,7 @@ TEST_F(TargetDeclTest, DependentTypes) {
using type = typename even<N - 1>::type::[[next]];
};
)cpp";
EXPECT_DECLS("DependentNameTypeLoc");
EXPECT_DECLS("DependentNameTypeLoc", );
}

TEST_F(TargetDeclTest, TypedefCascade) {
Expand Down Expand Up @@ -1263,14 +1263,14 @@ TEST_F(TargetDeclTest, ObjC) {
+ ([[id]])sharedInstance;
@end
)cpp";
EXPECT_DECLS("TypedefTypeLoc");
EXPECT_DECLS("TypedefTypeLoc", );

Code = R"cpp(
@interface Foo
+ ([[instancetype]])sharedInstance;
@end
)cpp";
EXPECT_DECLS("TypedefTypeLoc");
EXPECT_DECLS("TypedefTypeLoc", );
}

class FindExplicitReferencesTest : public ::testing::Test {
Expand Down
39 changes: 32 additions & 7 deletions clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
//===----------------------------------------------------------------------===//

#include "../../clang-tidy/ClangTidyCheck.h"
#include "../../clang-tidy/ClangTidyModule.h"
#include "../../clang-tidy/ClangTidyModuleRegistry.h"
#include "AST.h"
#include "CompileCommands.h"
#include "Compiler.h"
#include "Config.h"
#include "Diagnostics.h"
Expand All @@ -32,7 +29,6 @@
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TokenKinds.h"
#include "clang/Lex/PPCallbacks.h"
#include "clang/Tooling/Syntax/Tokens.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Testing/Annotations/Annotations.h"
Expand All @@ -41,6 +37,7 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <memory>
#include <string_view>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -347,9 +344,8 @@ TEST(ParsedASTTest, CollectsMainFileMacroExpansions) {
}
for (const auto &R : AST.getMacros().UnknownMacros)
MacroExpansionPositions.push_back(R.StartOffset);
EXPECT_THAT(
MacroExpansionPositions,
testing::UnorderedElementsAreArray(TestCase.points()));
EXPECT_THAT(MacroExpansionPositions,
testing::UnorderedElementsAreArray(TestCase.points()));
}

MATCHER_P(withFileName, Inc, "") { return arg.FileName == Inc; }
Expand Down Expand Up @@ -768,6 +764,35 @@ TEST(ParsedASTTest, GracefulFailureOnAssemblyFile) {
<< "Should not try to build AST for assembly source file";
}

TEST(ParsedASTTest, PreambleWithDifferentTarget) {
constexpr std::string_view kPreambleTarget = "x86_64";
// Specifically picking __builtin_va_list as it triggers crashes when
// switching to wasm.
// It's due to different predefined types in different targets.
auto TU = TestTU::withHeaderCode("void foo(__builtin_va_list);");
TU.Code = "void bar() { foo(2); }";
TU.ExtraArgs.emplace_back("-target");
TU.ExtraArgs.emplace_back(kPreambleTarget);
const auto Preamble = TU.preamble();

// Switch target to wasm.
TU.ExtraArgs.pop_back();
TU.ExtraArgs.emplace_back("wasm32");

IgnoreDiagnostics Diags;
MockFS FS;
auto Inputs = TU.inputs(FS);
auto CI = buildCompilerInvocation(Inputs, Diags);
ASSERT_TRUE(CI) << "Failed to build compiler invocation";

auto AST = ParsedAST::build(testPath(TU.Filename), std::move(Inputs),
std::move(CI), {}, Preamble);

ASSERT_TRUE(AST);
// We use the target from preamble, not with the most-recent flags.
EXPECT_EQ(AST->getASTContext().getTargetInfo().getTriple().getArchName(),
llvm::StringRef(kPreambleTarget));
}
} // namespace
} // namespace clangd
} // namespace clang
24 changes: 24 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ Improvements to clang-tidy
similar fashion to what `-header-filter` does for header files.
- Improved :program:`check_clang_tidy.py` script. Added argument `-export-fixes`
to aid in clang-tidy and test development.
- Fixed bug where big values for unsigned check options overflowed into negative values
when being printed with ``--dump-config``.

- Fixed ``--verify-config`` option not properly parsing checks when using the
literal operator in the ``.clang-tidy`` config.

New checks
^^^^^^^^^^
Expand All @@ -112,6 +117,13 @@ New checks
Detects error-prone Curiously Recurring Template Pattern usage, when the CRTP
can be constructed outside itself and the derived class.

- New :doc:`bugprone-return-const-ref-from-parameter
<clang-tidy/checks/bugprone/return-const-ref-from-parameter>` check.

Detects return statements that return a constant reference parameter as constant
reference. This may cause use-after-free errors if the caller uses xvalues as
arguments.

- New :doc:`bugprone-suspicious-stringview-data-usage
<clang-tidy/checks/bugprone/suspicious-stringview-data-usage>` check.

Expand Down Expand Up @@ -147,10 +159,18 @@ Changes in existing checks
<clang-tidy/checks/bugprone/assert-side-effect>` check by detecting side
effect from calling a method with non-const reference parameters.

- Improved :doc:`bugprone-forwarding-reference-overload
<clang-tidy/checks/bugprone/forwarding-reference-overload>`
check to ignore deleted constructors which won't hide other overloads.

- Improved :doc:`bugprone-inc-dec-in-conditions
<clang-tidy/checks/bugprone/inc-dec-in-conditions>` check to ignore code
within unevaluated contexts, such as ``decltype``.

- Improved :doc:`bugprone-lambda-function-name<clang-tidy/checks/bugprone/lambda-function-name>`
check by ignoring ``__func__`` macro in lambda captures, initializers of
default parameters and nested function declarations.

- Improved :doc:`bugprone-non-zero-enum-to-bool-conversion
<clang-tidy/checks/bugprone/non-zero-enum-to-bool-conversion>` check by
eliminating false positives resulting from direct usage of bitwise operators
Expand Down Expand Up @@ -253,6 +273,10 @@ Changes in existing checks
<clang-tidy/checks/modernize/use-override>` check to also remove any trailing
whitespace when deleting the ``virtual`` keyword.

- Improved :doc:`modernize-use-starts-ends-with
<clang-tidy/checks/modernize/use-starts-ends-with>` check to also handle
calls to ``compare`` method.

- Improved :doc:`modernize-use-using <clang-tidy/checks/modernize/use-using>`
check by adding support for detection of typedefs declared on function level.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.. title:: clang-tidy - bugprone-return-const-ref-from-parameter

bugprone-return-const-ref-from-parameter
========================================

Detects return statements that return a constant reference parameter as constant
reference. This may cause use-after-free errors if the caller uses xvalues as
arguments.

In C++, constant reference parameters can accept xvalues which will be destructed
after the call. When the function returns such a parameter also as constant reference,
then the returned reference can be used after the object it refers to has been
destroyed.

Example
-------

.. code-block:: c++

struct S {
int v;
S(int);
~S();
};

const S &fn(const S &a) {
return a;
}

const S& s = fn(S{1});
s.v; // use after free
9 changes: 5 additions & 4 deletions clang-tools-extra/docs/clang-tidy/checks/list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Clang-Tidy Checks
:doc:`bugprone-posix-return <bugprone/posix-return>`, "Yes"
:doc:`bugprone-redundant-branch-condition <bugprone/redundant-branch-condition>`, "Yes"
:doc:`bugprone-reserved-identifier <bugprone/reserved-identifier>`, "Yes"
:doc:`bugprone-return-const-ref-from-parameter <bugprone/return-const-ref-from-parameter>`
:doc:`bugprone-shared-ptr-array-mismatch <bugprone/shared-ptr-array-mismatch>`, "Yes"
:doc:`bugprone-signal-handler <bugprone/signal-handler>`,
:doc:`bugprone-signed-char-misuse <bugprone/signed-char-misuse>`,
Expand Down Expand Up @@ -341,9 +342,9 @@ Clang-Tidy Checks
:doc:`portability-std-allocator-const <portability/std-allocator-const>`,
:doc:`readability-avoid-const-params-in-decls <readability/avoid-const-params-in-decls>`, "Yes"
:doc:`readability-avoid-nested-conditional-operator <readability/avoid-nested-conditional-operator>`,
:doc:`readability-avoid-return-with-void-value <readability/avoid-return-with-void-value>`,
:doc:`readability-avoid-return-with-void-value <readability/avoid-return-with-void-value>`, "Yes"
:doc:`readability-avoid-unconditional-preprocessor-if <readability/avoid-unconditional-preprocessor-if>`,
:doc:`readability-braces-around-statements <readability/braces-around-statements>`, "Yes"
:doc:`readability-braces-around-statements <readability/braces-around-statements>`,
:doc:`readability-const-return-type <readability/const-return-type>`, "Yes"
:doc:`readability-container-contains <readability/container-contains>`, "Yes"
:doc:`readability-container-data-pointer <readability/container-data-pointer>`, "Yes"
Expand Down Expand Up @@ -529,12 +530,12 @@ Clang-Tidy Checks
:doc:`cppcoreguidelines-non-private-member-variables-in-classes <cppcoreguidelines/non-private-member-variables-in-classes>`, :doc:`misc-non-private-member-variables-in-classes <misc/non-private-member-variables-in-classes>`,
:doc:`cppcoreguidelines-use-default-member-init <cppcoreguidelines/use-default-member-init>`, :doc:`modernize-use-default-member-init <modernize/use-default-member-init>`, "Yes"
:doc:`fuchsia-header-anon-namespaces <fuchsia/header-anon-namespaces>`, :doc:`google-build-namespaces <google/build-namespaces>`,
:doc:`google-readability-braces-around-statements <google/readability-braces-around-statements>`, :doc:`readability-braces-around-statements <readability/braces-around-statements>`, "Yes"
:doc:`google-readability-braces-around-statements <google/readability-braces-around-statements>`, :doc:`readability-braces-around-statements <readability/braces-around-statements>`,
:doc:`google-readability-function-size <google/readability-function-size>`, :doc:`readability-function-size <readability/function-size>`,
:doc:`google-readability-namespace-comments <google/readability-namespace-comments>`, :doc:`llvm-namespace-comment <llvm/namespace-comment>`,
:doc:`hicpp-avoid-c-arrays <hicpp/avoid-c-arrays>`, :doc:`modernize-avoid-c-arrays <modernize/avoid-c-arrays>`,
:doc:`hicpp-avoid-goto <hicpp/avoid-goto>`, :doc:`cppcoreguidelines-avoid-goto <cppcoreguidelines/avoid-goto>`,
:doc:`hicpp-braces-around-statements <hicpp/braces-around-statements>`, :doc:`readability-braces-around-statements <readability/braces-around-statements>`, "Yes"
:doc:`hicpp-braces-around-statements <hicpp/braces-around-statements>`, :doc:`readability-braces-around-statements <readability/braces-around-statements>`,
:doc:`hicpp-deprecated-headers <hicpp/deprecated-headers>`, :doc:`modernize-deprecated-headers <modernize/deprecated-headers>`, "Yes"
:doc:`hicpp-explicit-conversions <hicpp/explicit-conversions>`, :doc:`google-explicit-constructor <google/explicit-constructor>`, "Yes"
:doc:`hicpp-function-size <hicpp/function-size>`, :doc:`readability-function-size <readability/function-size>`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
modernize-use-starts-ends-with
==============================

Checks whether a ``find`` or ``rfind`` result is compared with 0 and suggests
replacing with ``starts_with`` when the method exists in the class. Notably,
this will work with ``std::string`` and ``std::string_view``.
Checks for common roundabout ways to express ``starts_with`` and ``ends_with``
and suggests replacing with ``starts_with`` when the method is available.
Notably, this will work with ``std::string`` and ``std::string_view``.

.. code-block:: c++

std::string s = "...";
if (s.find("prefix") == 0) { /* do something */ }
if (s.rfind("prefix", 0) == 0) { /* do something */ }
if (s.compare(0, strlen("prefix"), "prefix") == 0) { /* do something */ }
becomes

Expand All @@ -20,3 +21,4 @@ becomes
std::string s = "...";
if (s.starts_with("prefix")) { /* do something */ }
if (s.starts_with("prefix")) { /* do something */ }
if (s.starts_with("prefix")) { /* do something */ }
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ struct basic_string {
int compare(const C* s) const;
int compare(size_type pos, size_type len, const _Type&) const;
int compare(size_type pos, size_type len, const C* s) const;
template<class StringViewLike>
int compare(size_type pos1, size_type count1, const StringViewLike& t) const;

size_type find(const _Type& str, size_type pos = 0) const;
size_type find(const C* s, size_type pos = 0) const;
Expand Down Expand Up @@ -129,6 +131,8 @@ bool operator!=(const char*, const std::string&);
bool operator==(const std::wstring&, const std::wstring&);
bool operator==(const std::wstring&, const wchar_t*);
bool operator==(const wchar_t*, const std::wstring&);

size_t strlen(const char* str);
}

#endif // _STRING_
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
#include "stddef.h"

void *memcpy(void *dest, const void *src, size_t n);
size_t strlen(const char* str);

#endif // _STRING_H_
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// RUN: %check_clang_tidy %s abseil-redundant-strcat-calls %t -- -- -isystem %clang_tidy_headers
#include <string>

int strlen(const char *);

namespace absl {

class string_view {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,13 @@ class Test10 {
Test10(T &&Item, E e)
: e(e){}
};

// A deleted ctor cannot hide anything
class Test11 {
public:
template <typename T>
Test11(T&&) = delete;

Test11(const Test11 &) = default;
Test11(Test11 &&) = default;
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ void Positives() {
// CHECK-MESSAGES-NO-CONFIG: :[[@LINE-1]]:8: warning: inside a lambda, '__FUNCTION__' expands to the name of the function call operator; consider capturing the name of the enclosing function explicitly [bugprone-lambda-function-name]
[] { EMBED_IN_ANOTHER_MACRO1; }();
// CHECK-MESSAGES-NO-CONFIG: :[[@LINE-1]]:8: warning: inside a lambda, '__func__' expands to the name of the function call operator; consider capturing the name of the enclosing function explicitly [bugprone-lambda-function-name]
[] {
__func__;
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: inside a lambda, '__func__' expands to the name of the function call operator; consider capturing the name of the enclosing function explicitly [bugprone-lambda-function-name]
struct S {
void f() {
__func__;
[] {
__func__;
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: inside a lambda, '__func__' expands to the name of the function call operator; consider capturing the name of the enclosing function explicitly [bugprone-lambda-function-name]
}();
__func__;
}
};
__func__;
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: inside a lambda, '__func__' expands to the name of the function call operator; consider capturing the name of the enclosing function explicitly [bugprone-lambda-function-name]
}();
}

#define FUNC_MACRO_WITH_FILE_AND_LINE Foo(__func__, __FILE__, __LINE__)
Expand All @@ -40,4 +56,7 @@ void Negatives() {
[] { FUNC_MACRO_WITH_FILE_AND_LINE; }();
[] { FUNCTION_MACRO_WITH_FILE_AND_LINE; }();
[] { EMBED_IN_ANOTHER_MACRO2; }();

[] (const char* func = __func__) { func; }();
[func=__func__] { func; }();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// RUN: %check_clang_tidy %s bugprone-return-const-ref-from-parameter %t

using T = int;
using TConst = int const;
using TConstRef = int const&;

namespace invalid {

int const &f1(int const &a) { return a; }
// CHECK-MESSAGES: :[[@LINE-1]]:38: warning: returning a constant reference parameter

int const &f2(T const &a) { return a; }
// CHECK-MESSAGES: :[[@LINE-1]]:36: warning: returning a constant reference parameter

int const &f3(TConstRef a) { return a; }
// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: returning a constant reference parameter

int const &f4(TConst &a) { return a; }
// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: returning a constant reference parameter

} // namespace invalid

namespace valid {

int const &f1(int &a) { return a; }

int const &f2(int &&a) { return a; }

int f1(int const &a) { return a; }

} // namespace valid
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: %check_clang_tidy -std=c++20 %s modernize-use-starts-ends-with %t -- \
// RUN: -- -isystem %clang_tidy_headers

#include <string.h>
#include <string>

std::string foo(std::string);
Expand Down Expand Up @@ -158,10 +159,64 @@ void test(std::string s, std::string_view sv, sub_string ss, sub_sub_string sss,
// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use startsWith
// CHECK-FIXES: puvi.startsWith("a");

s.compare(0, 1, "a") == 0;
// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with instead of compare() == 0
// CHECK-FIXES: s.starts_with("a");

s.compare(0, 1, "a") != 0;
// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with instead of compare() != 0
// CHECK-FIXES: !s.starts_with("a");

s.compare(0, strlen("a"), "a") == 0;
// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
// CHECK-FIXES: s.starts_with("a");

s.compare(0, std::strlen("a"), "a") == 0;
// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
// CHECK-FIXES: s.starts_with("a");

s.compare(0, std::strlen(("a")), "a") == 0;
// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
// CHECK-FIXES: s.starts_with("a");

s.compare(0, std::strlen(("a")), (("a"))) == 0;
// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
// CHECK-FIXES: s.starts_with("a");

s.compare(0, s.size(), s) == 0;
// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
// CHECK-FIXES: s.starts_with(s);

s.compare(0, s.length(), s) == 0;
// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
// CHECK-FIXES: s.starts_with(s);

0 != s.compare(0, sv.length(), sv);
// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
// CHECK-FIXES: s.starts_with(sv);

#define LENGTH(x) (x).length()
s.compare(0, LENGTH(s), s) == 0;
// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
// CHECK-FIXES: s.starts_with(s);

s.compare(ZERO, LENGTH(s), s) == ZERO;
// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
// CHECK-FIXES: s.starts_with(s);

s.compare(ZERO, LENGTH(sv), sv) != 0;
// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
// CHECK-FIXES: !s.starts_with(sv);

// Expressions that don't trigger the check are here.
#define EQ(x, y) ((x) == (y))
EQ(s.find("a"), 0);

#define DOTFIND(x, y) (x).find(y)
DOTFIND(s, "a") == 0;

#define STARTS_WITH_COMPARE(x, y) (x).compare(0, (x).size(), (y))
STARTS_WITH_COMPARE(s, s) == 0;

s.compare(0, 1, "ab") == 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
InheritParentConfig: true
Checks: 'misc-throw-by-value-catch-by-reference'
CheckOptions:
misc-throw-by-value-catch-by-reference.MaxSize: '1152921504606846976'
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,11 @@

// Validate that check options are printed in alphabetical order:
// RUN: clang-tidy --checks="-*,readability-identifier-naming" --dump-config %S/Inputs/config-files/- -- | grep "readability-identifier-naming\." | sort --check

// Dumped config does not overflow for unsigned options
// RUN: clang-tidy --dump-config \
// RUN: --checks="-*,misc-throw-by-value-catch-by-reference" \
// RUN: -- | grep -v -q "misc-throw-by-value-catch-by-reference.MaxSize: '-1'"

// RUN: clang-tidy --dump-config %S/Inputs/config-files/5/- \
// RUN: -- | grep -q "misc-throw-by-value-catch-by-reference.MaxSize: '1152921504606846976'"
12 changes: 12 additions & 0 deletions clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,15 @@
// CHECK-VERIFY: command-line option '-checks': warning: check glob 'bad*glob' doesn't match any known check [-verify-config]
// CHECK-VERIFY: command-line option '-checks': warning: unknown check 'llvm-includeorder'; did you mean 'llvm-include-order' [-verify-config]
// CHECK-VERIFY: command-line option '-checks': warning: unknown check 'my-made-up-check' [-verify-config]

// RUN: echo -e 'Checks: |\n bugprone-argument-comment\n bugprone-assert-side-effect,\n bugprone-bool-pointer-implicit-conversion\n readability-use-anyof*' > %T/MyClangTidyConfig
// RUN: clang-tidy -verify-config \
// RUN: --config-file=%T/MyClangTidyConfig | FileCheck %s -check-prefix=CHECK-VERIFY-BLOCK-OK
// CHECK-VERIFY-BLOCK-OK: No config errors detected.

// RUN: echo -e 'Checks: |\n bugprone-arguments-*\n bugprone-assert-side-effects\n bugprone-bool-pointer-implicit-conversion' > %T/MyClangTidyConfigBad
// RUN: not clang-tidy -verify-config \
// RUN: --config-file=%T/MyClangTidyConfigBad 2>&1 | FileCheck %s -check-prefix=CHECK-VERIFY-BLOCK-BAD
// CHECK-VERIFY-BLOCK-BAD: command-line option '-config': warning: check glob 'bugprone-arguments-*' doesn't match any known check [-verify-config]
// CHECK-VERIFY-BLOCK-BAD: command-line option '-config': warning: unknown check 'bugprone-assert-side-effects'; did you mean 'bugprone-assert-side-effect' [-verify-config]

1 change: 1 addition & 0 deletions clang/cmake/caches/Apple-stage2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
set(LLVM_ENABLE_MODULES ON CACHE BOOL "")
set(LLVM_EXTERNALIZE_DEBUGINFO ON CACHE BOOL "")
set(LLVM_ENABLE_EXPORTED_SYMBOLS_IN_EXECUTABLES OFF CACHE BOOL "")
set(LLVM_PLUGIN_SUPPORT OFF CACHE BOOL "")
set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
set(CLANG_SPAWN_CC1 ON CACHE BOOL "")
set(BUG_REPORT_URL "http://developer.apple.com/bugreporter/" CACHE STRING "")
Expand Down
1 change: 0 additions & 1 deletion clang/cmake/caches/Fuchsia.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ set(_FUCHSIA_BOOTSTRAP_PASSTHROUGH
LLDB_EMBED_PYTHON_HOME
LLDB_PYTHON_HOME
LLDB_PYTHON_RELATIVE_PATH
LLDB_TEST_USE_VENDOR_PACKAGES
LLDB_TEST_USER_ARGS
Python3_EXECUTABLE
Python3_LIBRARIES
Expand Down
5 changes: 4 additions & 1 deletion clang/docs/ClangOffloadBundler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -518,11 +518,14 @@ The compressed offload bundle begins with a header followed by the compressed bi
This is a unique identifier to distinguish compressed offload bundles. The value is the string 'CCOB' (Compressed Clang Offload Bundle).

- **Version Number (16-bit unsigned int)**:
This denotes the version of the compressed offload bundle format. The current version is `1`.
This denotes the version of the compressed offload bundle format. The current version is `2`.

- **Compression Method (16-bit unsigned int)**:
This field indicates the compression method used. The value corresponds to either `zlib` or `zstd`, represented as a 16-bit unsigned integer cast from the LLVM compression enumeration.

- **Total File Size (32-bit unsigned int)**:
This is the total size (in bytes) of the file, including the header. Available in version 2 and above.

- **Uncompressed Binary Size (32-bit unsigned int)**:
This is the size (in bytes) of the binary data before it was compressed.

Expand Down
3 changes: 2 additions & 1 deletion clang/docs/LanguageExtensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,8 @@ The following type trait primitives are supported by Clang. Those traits marked
were made trivially relocatable via the ``clang::trivial_abi`` attribute.
* ``__is_trivially_equality_comparable`` (Clang): Returns true if comparing two
objects of the provided type is known to be equivalent to comparing their
value representations.
object representations. Note that types containing padding bytes are never
trivially equality comparable.
* ``__is_unbounded_array`` (C++, GNU, Microsoft, Embarcadero)
* ``__is_union`` (C++, GNU, Microsoft, Embarcadero)
* ``__is_unsigned`` (C++, Embarcadero):
Expand Down
41 changes: 41 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ sections with improvements to Clang's support for those languages.

C++ Language Changes
--------------------
- Implemented ``_BitInt`` literal suffixes ``__wb`` or ``__WB`` as a Clang extension with ``unsigned`` modifiers also allowed. (#GH85223).

C++20 Feature Support
^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -179,6 +180,9 @@ C23 Feature Support
- Clang now supports `N3018 The constexpr specifier for object definitions`
<https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3018.htm>`_.

- Properly promote bit-fields of bit-precise integer types to the field's type
rather than to ``int``. #GH87641

Non-comprehensive list of changes in this release
-------------------------------------------------

Expand Down Expand Up @@ -248,6 +252,8 @@ Modified Compiler Flags
f3 *c = (f3 *)x;
}
- Carved out ``-Wformat`` warning about scoped enums into a subwarning and
make it controlled by ``-Wformat-pedantic``. Fixes #GH88595.

Removed Compiler Flags
-------------------------
Expand Down Expand Up @@ -287,6 +293,9 @@ Attribute Changes in Clang
This allows the ``_Nullable`` and ``_Nonnull`` family of type attributes to
apply to this class.

- Clang now warns that the ``exclude_from_explicit_instantiation`` attribute
is ignored when applied to a local class or a member thereof.

Improvements to Clang's diagnostics
-----------------------------------
- Clang now applies syntax highlighting to the code snippets it
Expand Down Expand Up @@ -364,6 +373,8 @@ Improvements to Clang's diagnostics
- Clang now uses the correct type-parameter-key (``class`` or ``typename``) when printing
template template parameter declarations.

- Clang now diagnoses requires expressions with explicit object parameters.

Improvements to Clang's time-trace
----------------------------------

Expand Down Expand Up @@ -404,6 +415,9 @@ Bug Fixes in This Version
operator.
Fixes (#GH83267).

- Fix crash on ill-formed partial specialization with CRTP.
Fixes (#GH89374).

- Clang now correctly generates overloads for bit-precise integer types for
builtin operators in C++. Fixes #GH82998.

Expand All @@ -422,6 +436,14 @@ Bug Fixes in This Version

- Fixed an assertion failure on invalid InitListExpr in C89 mode (#GH88008).

- Clang will no longer diagnose an erroneous non-dependent ``switch`` condition
during instantiation, and instead will only diagnose it once, during checking
of the function template.

- Clang now allows the value of unroll count to be zero in ``#pragma GCC unroll`` and ``#pragma unroll``.
The values of 0 and 1 block any unrolling of the loop. This keeps the same behavior with GCC.
Fixes (`#88624 <https://github.com/llvm/llvm-project/issues/88624>`_).

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -525,6 +547,8 @@ Bug Fixes to C++ Support
- Fix an issue caused by not handling invalid cases when substituting into the parameter mapping of a constraint. Fixes (#GH86757).
- Fixed a bug that prevented member function templates of class templates declared with a deduced return type
from being explicitly specialized for a given implicit instantiation of the class template.
- Fixed a crash when ``this`` is used in a dependent class scope function template specialization
that instantiates to a static member function.

- Fix crash when inheriting from a cv-qualified type. Fixes #GH35603
- Fix a crash when the using enum declaration uses an anonymous enumeration. Fixes (#GH86790).
Expand All @@ -534,6 +558,12 @@ Bug Fixes to C++ Support
Fixes (#GH70604), (#GH79754), (#GH84163), (#GH84425), (#GH86054), (#GH86398), and (#GH86399).
- Fix a crash when deducing ``auto`` from an invalid dereference (#GH88329).
- Fix a crash in requires expression with templated base class member function. Fixes (#GH84020).
- Fix a crash caused by defined struct in a type alias template when the structure
has fields with dependent type. Fixes (#GH75221).
- Fix the Itanium mangling of lambdas defined in a member of a local class (#GH88906)
- Fixed a crash when trying to evaluate a user-defined ``static_assert`` message whose ``size()``
function returns a large or negative value. Fixes (#GH89407).
- Fixed a use-after-free bug in parsing of type constraints with default arguments that involve lambdas. (#GH67235)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -543,6 +573,9 @@ Bug Fixes to AST Handling
Miscellaneous Bug Fixes
^^^^^^^^^^^^^^^^^^^^^^^

- Fixed an infinite recursion in ASTImporter, on return type declared inside
body of C++11 lambda without trailing return (#GH68775).

Miscellaneous Clang Crashes Fixed
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -630,6 +663,12 @@ CUDA Support
AIX Support
^^^^^^^^^^^

- Introduced the ``-maix-small-local-dynamic-tls`` option to produce a faster
access sequence for local-dynamic TLS variables where the offset from the TLS
base is encoded as an immediate operand.
This access sequence is not used for TLS variables larger than 32KB, and is
currently only supported on 64-bit mode.

WebAssembly Support
^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -680,6 +719,8 @@ Static Analyzer
- Support C++23 static operator calls. (#GH84972)
- Fixed a crash in ``security.cert.env.InvalidPtr`` checker when accidentally
matched user-defined ``strerror`` and similar library functions. (GH#88181)
- Fixed a crash when storing through an address that refers to the address of
a label. (GH#89185)

New features
^^^^^^^^^^^^
Expand Down
24 changes: 24 additions & 0 deletions clang/docs/StandardCPlusPlusModules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,13 @@ violations with the flag enabled.
ABI Impacts
-----------

This section describes the new ABI changes brought by modules.

Only Itanium C++ ABI related change are mentioned

Mangling Names
~~~~~~~~~~~~~~

The declarations in a module unit which are not in the global module fragment have new linkage names.

For example,
Expand Down Expand Up @@ -520,6 +527,23 @@ is attached to the global module fragments. For example:

Now the linkage name of ``NS::foo()`` will be ``_ZN2NS3fooEv``.

Module Initializers
~~~~~~~~~~~~~~~~~~~

All the importable module units are required to emit an initializer function.
The initializer function should contain calls to importing modules first and
all the dynamic-initializers in the current module unit then.

Translation units explicitly or implicitly importing named modules must call
the initializer functions of the imported named modules within the sequence of
the dynamic-initializers in the TU. Initializations of entities at namespace
scope are appearance-ordered. This (recursively) extends into imported modules
at the point of appearance of the import declaration.

It is allowed to omit calls to importing modules if it is known empty.

It is allowed to omit calls to importing modules for which is known to be called.

Reduced BMI
-----------

Expand Down
3 changes: 3 additions & 0 deletions clang/docs/UsersManual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4921,6 +4921,9 @@ directory. Using the example installation above, this would mean passing
If the user links the program with the ``clang`` or ``clang-cl`` drivers, the
driver will pass this flag for them.

The auto-linking can be disabled with -fno-rtlib-defaultlib. If that flag is
used, pass the complete flag to required libraries as described for ASan below.

If the linker cannot find the appropriate library, it will emit an error like
this::

Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
/// initialization of another module).
struct PerModuleInitializers {
llvm::SmallVector<Decl*, 4> Initializers;
llvm::SmallVector<uint32_t, 4> LazyInitializers;
llvm::SmallVector<Decl::DeclID, 4> LazyInitializers;

void resolve(ASTContext &Ctx);
};
Expand Down Expand Up @@ -1059,7 +1059,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
/// or an ImportDecl nominating another module that has initializers.
void addModuleInitializer(Module *M, Decl *Init);

void addLazyModuleInitializers(Module *M, ArrayRef<uint32_t> IDs);
void addLazyModuleInitializers(Module *M, ArrayRef<Decl::DeclID> IDs);

/// Get the initializations to perform when importing a module, if any.
ArrayRef<Decl*> getModuleInitializers(Module *M);
Expand Down
27 changes: 27 additions & 0 deletions clang/include/clang/AST/ASTMutationListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace clang {
class FunctionTemplateDecl;
class Module;
class NamedDecl;
class NamespaceDecl;
class ObjCCategoryDecl;
class ObjCContainerDecl;
class ObjCInterfaceDecl;
Expand All @@ -35,6 +36,7 @@ namespace clang {
class QualType;
class RecordDecl;
class TagDecl;
class TranslationUnitDecl;
class ValueDecl;
class VarDecl;
class VarTemplateDecl;
Expand Down Expand Up @@ -147,6 +149,31 @@ class ASTMutationListener {
virtual void AddedAttributeToRecord(const Attr *Attr,
const RecordDecl *Record) {}

/// The parser find the named module declaration.
virtual void EnteringModulePurview() {}

/// An mangling number was added to a Decl
///
/// \param D The decl that got a mangling number
///
/// \param Number The mangling number that was added to the Decl
virtual void AddedManglingNumber(const Decl *D, unsigned Number) {}

/// An static local number was added to a Decl
///
/// \param D The decl that got a static local number
///
/// \param Number The static local number that was added to the Decl
virtual void AddedStaticLocalNumbers(const Decl *D, unsigned Number) {}

/// An anonymous namespace was added the translation unit decl
///
/// \param TU The translation unit decl that got a new anonymous namespace
///
/// \param AnonNamespace The anonymous namespace that was added
virtual void AddedAnonymousNamespace(const TranslationUnitDecl *TU,
NamespaceDecl *AnonNamespace) {}

// NOTE: If new methods are added they should also be added to
// MultiplexASTMutationListener.
};
Expand Down
6 changes: 6 additions & 0 deletions clang/include/clang/AST/ASTNodeTraverser.h
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,12 @@ class ASTNodeTraverser
Visit(R);
}

void VisitTypeTraitExpr(const TypeTraitExpr *E) {
// Argument types are not children of the TypeTraitExpr.
for (auto *A : E->getArgs())
Visit(A->getType());
}

void VisitLambdaExpr(const LambdaExpr *Node) {
if (Traversal == TK_IgnoreUnlessSpelledInSource) {
for (unsigned I = 0, N = Node->capture_size(); I != N; ++I) {
Expand Down
50 changes: 25 additions & 25 deletions clang/include/clang/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class TranslationUnitDecl : public Decl,
ASTContext &getASTContext() const { return Ctx; }

NamespaceDecl *getAnonymousNamespace() const { return AnonymousNamespace; }
void setAnonymousNamespace(NamespaceDecl *D) { AnonymousNamespace = D; }
void setAnonymousNamespace(NamespaceDecl *D);

static TranslationUnitDecl *Create(ASTContext &C);

Expand Down Expand Up @@ -157,7 +157,7 @@ class PragmaCommentDecl final
SourceLocation CommentLoc,
PragmaMSCommentKind CommentKind,
StringRef Arg);
static PragmaCommentDecl *CreateDeserialized(ASTContext &C, unsigned ID,
static PragmaCommentDecl *CreateDeserialized(ASTContext &C, DeclID ID,
unsigned ArgSize);

PragmaMSCommentKind getCommentKind() const { return CommentKind; }
Expand Down Expand Up @@ -192,7 +192,7 @@ class PragmaDetectMismatchDecl final
SourceLocation Loc, StringRef Name,
StringRef Value);
static PragmaDetectMismatchDecl *
CreateDeserialized(ASTContext &C, unsigned ID, unsigned NameValueSize);
CreateDeserialized(ASTContext &C, DeclID ID, unsigned NameValueSize);

StringRef getName() const { return getTrailingObjects<char>(); }
StringRef getValue() const { return getTrailingObjects<char>() + ValueStart; }
Expand Down Expand Up @@ -518,7 +518,7 @@ class LabelDecl : public NamedDecl {
static LabelDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation IdentL, IdentifierInfo *II,
SourceLocation GnuLabelL);
static LabelDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static LabelDecl *CreateDeserialized(ASTContext &C, DeclID ID);

LabelStmt *getStmt() const { return TheStmt; }
void setStmt(LabelStmt *T) { TheStmt = T; }
Expand Down Expand Up @@ -581,7 +581,7 @@ class NamespaceDecl : public NamedDecl, public DeclContext,
IdentifierInfo *Id, NamespaceDecl *PrevDecl,
bool Nested);

static NamespaceDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static NamespaceDecl *CreateDeserialized(ASTContext &C, DeclID ID);

using redecl_range = redeclarable_base::redecl_range;
using redecl_iterator = redeclarable_base::redecl_iterator;
Expand Down Expand Up @@ -1146,7 +1146,7 @@ class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
const IdentifierInfo *Id, QualType T,
TypeSourceInfo *TInfo, StorageClass S);

static VarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static VarDecl *CreateDeserialized(ASTContext &C, DeclID ID);

SourceRange getSourceRange() const override LLVM_READONLY;

Expand Down Expand Up @@ -1728,7 +1728,7 @@ class ImplicitParamDecl : public VarDecl {
static ImplicitParamDecl *Create(ASTContext &C, QualType T,
ImplicitParamKind ParamKind);

static ImplicitParamDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static ImplicitParamDecl *CreateDeserialized(ASTContext &C, DeclID ID);

ImplicitParamDecl(ASTContext &C, DeclContext *DC, SourceLocation IdLoc,
const IdentifierInfo *Id, QualType Type,
Expand Down Expand Up @@ -1782,7 +1782,7 @@ class ParmVarDecl : public VarDecl {
TypeSourceInfo *TInfo, StorageClass S,
Expr *DefArg);

static ParmVarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static ParmVarDecl *CreateDeserialized(ASTContext &C, DeclID ID);

SourceRange getSourceRange() const override LLVM_READONLY;

Expand Down Expand Up @@ -2178,7 +2178,7 @@ class FunctionDecl : public DeclaratorDecl,
bool hasWrittenPrototype, ConstexprSpecKind ConstexprKind,
Expr *TrailingRequiresClause);

static FunctionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static FunctionDecl *CreateDeserialized(ASTContext &C, DeclID ID);

DeclarationNameInfo getNameInfo() const {
return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
Expand Down Expand Up @@ -3136,7 +3136,7 @@ class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
InClassInitStyle InitStyle);

static FieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static FieldDecl *CreateDeserialized(ASTContext &C, DeclID ID);

/// Returns the index of this field within its record,
/// as appropriate for passing to ASTRecordLayout::getFieldOffset.
Expand All @@ -3149,7 +3149,7 @@ class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
bool isBitField() const { return BitField; }

/// Determines whether this is an unnamed bitfield.
bool isUnnamedBitfield() const { return isBitField() && !getDeclName(); }
bool isUnnamedBitField() const { return isBitField() && !getDeclName(); }

/// Determines whether this field is a
/// representative for an anonymous struct or union. Such fields are
Expand Down Expand Up @@ -3311,7 +3311,7 @@ class EnumConstantDecl : public ValueDecl,
SourceLocation L, IdentifierInfo *Id,
QualType T, Expr *E,
const llvm::APSInt &V);
static EnumConstantDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static EnumConstantDecl *CreateDeserialized(ASTContext &C, DeclID ID);

const Expr *getInitExpr() const { return (const Expr*) Init; }
Expr *getInitExpr() { return (Expr*) Init; }
Expand Down Expand Up @@ -3357,7 +3357,7 @@ class IndirectFieldDecl : public ValueDecl,
QualType T,
llvm::MutableArrayRef<NamedDecl *> CH);

static IndirectFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static IndirectFieldDecl *CreateDeserialized(ASTContext &C, DeclID ID);

using chain_iterator = ArrayRef<NamedDecl *>::const_iterator;

Expand Down Expand Up @@ -3542,7 +3542,7 @@ class TypedefDecl : public TypedefNameDecl {
static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation StartLoc, SourceLocation IdLoc,
const IdentifierInfo *Id, TypeSourceInfo *TInfo);
static TypedefDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static TypedefDecl *CreateDeserialized(ASTContext &C, DeclID ID);

SourceRange getSourceRange() const override LLVM_READONLY;

Expand All @@ -3567,7 +3567,7 @@ class TypeAliasDecl : public TypedefNameDecl {
static TypeAliasDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation StartLoc, SourceLocation IdLoc,
const IdentifierInfo *Id, TypeSourceInfo *TInfo);
static TypeAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static TypeAliasDecl *CreateDeserialized(ASTContext &C, DeclID ID);

SourceRange getSourceRange() const override LLVM_READONLY;

Expand Down Expand Up @@ -3977,7 +3977,7 @@ class EnumDecl : public TagDecl {
IdentifierInfo *Id, EnumDecl *PrevDecl,
bool IsScoped, bool IsScopedUsingClassTag,
bool IsFixed);
static EnumDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static EnumDecl *CreateDeserialized(ASTContext &C, DeclID ID);

/// Overrides to provide correct range when there's an enum-base specifier
/// with forward declarations.
Expand Down Expand Up @@ -4182,7 +4182,7 @@ class RecordDecl : public TagDecl {
static RecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
SourceLocation StartLoc, SourceLocation IdLoc,
IdentifierInfo *Id, RecordDecl* PrevDecl = nullptr);
static RecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
static RecordDecl *CreateDeserialized(const ASTContext &C, DeclID ID);

RecordDecl *getPreviousDecl() {
return cast_or_null<RecordDecl>(
Expand Down Expand Up @@ -4433,7 +4433,7 @@ class FileScopeAsmDecl : public Decl {
StringLiteral *Str, SourceLocation AsmLoc,
SourceLocation RParenLoc);

static FileScopeAsmDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static FileScopeAsmDecl *CreateDeserialized(ASTContext &C, DeclID ID);

SourceLocation getAsmLoc() const { return getLocation(); }
SourceLocation getRParenLoc() const { return RParenLoc; }
Expand Down Expand Up @@ -4469,7 +4469,7 @@ class TopLevelStmtDecl : public Decl, public DeclContext {

public:
static TopLevelStmtDecl *Create(ASTContext &C, Stmt *Statement);
static TopLevelStmtDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static TopLevelStmtDecl *CreateDeserialized(ASTContext &C, DeclID ID);

SourceRange getSourceRange() const override LLVM_READONLY;
Stmt *getStmt() { return Statement; }
Expand Down Expand Up @@ -4563,7 +4563,7 @@ class BlockDecl : public Decl, public DeclContext {

public:
static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L);
static BlockDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static BlockDecl *CreateDeserialized(ASTContext &C, DeclID ID);

SourceLocation getCaretLocation() const { return getLocation(); }

Expand Down Expand Up @@ -4717,7 +4717,7 @@ class CapturedDecl final

static CapturedDecl *Create(ASTContext &C, DeclContext *DC,
unsigned NumParams);
static CapturedDecl *CreateDeserialized(ASTContext &C, unsigned ID,
static CapturedDecl *CreateDeserialized(ASTContext &C, DeclID ID,
unsigned NumParams);

Stmt *getBody() const override;
Expand Down Expand Up @@ -4851,7 +4851,7 @@ class ImportDecl final : public Decl,
SourceLocation EndLoc);

/// Create a new, deserialized module import declaration.
static ImportDecl *CreateDeserialized(ASTContext &C, unsigned ID,
static ImportDecl *CreateDeserialized(ASTContext &C, DeclID ID,
unsigned NumLocations);

/// Retrieve the module that was imported by the import declaration.
Expand Down Expand Up @@ -4892,7 +4892,7 @@ class ExportDecl final : public Decl, public DeclContext {
public:
static ExportDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation ExportLoc);
static ExportDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static ExportDecl *CreateDeserialized(ASTContext &C, DeclID ID);

SourceLocation getExportLoc() const { return getLocation(); }
SourceLocation getRBraceLoc() const { return RBraceLoc; }
Expand Down Expand Up @@ -4931,7 +4931,7 @@ class EmptyDecl : public Decl {
public:
static EmptyDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation L);
static EmptyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static EmptyDecl *CreateDeserialized(ASTContext &C, DeclID ID);

static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classofKind(Kind K) { return K == Empty; }
Expand All @@ -4957,7 +4957,7 @@ class HLSLBufferDecl final : public NamedDecl, public DeclContext {
bool CBuffer, SourceLocation KwLoc,
IdentifierInfo *ID, SourceLocation IDLoc,
SourceLocation LBrace);
static HLSLBufferDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static HLSLBufferDecl *CreateDeserialized(ASTContext &C, DeclID ID);

SourceRange getSourceRange() const override LLVM_READONLY {
return SourceRange(getLocStart(), RBraceLoc);
Expand Down
9 changes: 6 additions & 3 deletions clang/include/clang/AST/DeclBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ class alignas(8) Decl {
ModulePrivate
};

/// An ID number that refers to a declaration in an AST file.
using DeclID = uint32_t;

protected:
/// The next declaration within the same lexical
/// DeclContext. These pointers form the linked list that is
Expand Down Expand Up @@ -358,7 +361,7 @@ class alignas(8) Decl {
/// \param Ctx The context in which we will allocate memory.
/// \param ID The global ID of the deserialized declaration.
/// \param Extra The amount of extra space to allocate after the object.
void *operator new(std::size_t Size, const ASTContext &Ctx, unsigned ID,
void *operator new(std::size_t Size, const ASTContext &Ctx, DeclID ID,
std::size_t Extra = 0);

/// Allocate memory for a non-deserialized declaration.
Expand Down Expand Up @@ -776,9 +779,9 @@ class alignas(8) Decl {

/// Retrieve the global declaration ID associated with this
/// declaration, which specifies where this Decl was loaded from.
unsigned getGlobalID() const {
DeclID getGlobalID() const {
if (isFromASTFile())
return *((const unsigned*)this - 1);
return *((const DeclID *)this - 1);
return 0;
}

Expand Down
52 changes: 26 additions & 26 deletions clang/include/clang/AST/DeclCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class AccessSpecDecl : public Decl {
return new (C, DC) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
}

static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static AccessSpecDecl *CreateDeserialized(ASTContext &C, DeclID ID);

// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
Expand Down Expand Up @@ -579,7 +579,7 @@ class CXXRecordDecl : public RecordDecl {
TypeSourceInfo *Info, SourceLocation Loc,
unsigned DependencyKind, bool IsGeneric,
LambdaCaptureDefault CaptureDefault);
static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
static CXXRecordDecl *CreateDeserialized(const ASTContext &C, DeclID ID);

bool isDynamicClass() const {
return data().Polymorphic || data().NumVBases != 0;
Expand Down Expand Up @@ -1980,7 +1980,7 @@ class CXXDeductionGuideDecl : public FunctionDecl {
CXXConstructorDecl *Ctor = nullptr,
DeductionCandidate Kind = DeductionCandidate::Normal);

static CXXDeductionGuideDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static CXXDeductionGuideDecl *CreateDeserialized(ASTContext &C, DeclID ID);

ExplicitSpecifier getExplicitSpecifier() { return ExplicitSpec; }
const ExplicitSpecifier getExplicitSpecifier() const { return ExplicitSpec; }
Expand Down Expand Up @@ -2035,7 +2035,7 @@ class RequiresExprBodyDecl : public Decl, public DeclContext {
static RequiresExprBodyDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation StartLoc);

static RequiresExprBodyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static RequiresExprBodyDecl *CreateDeserialized(ASTContext &C, DeclID ID);

// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
Expand Down Expand Up @@ -2078,7 +2078,7 @@ class CXXMethodDecl : public FunctionDecl {
ConstexprSpecKind ConstexprKind, SourceLocation EndLocation,
Expr *TrailingRequiresClause = nullptr);

static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static CXXMethodDecl *CreateDeserialized(ASTContext &C, DeclID ID);

bool isStatic() const;
bool isInstance() const { return !isStatic(); }
Expand Down Expand Up @@ -2579,7 +2579,7 @@ class CXXConstructorDecl final
friend class ASTDeclWriter;
friend TrailingObjects;

static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID,
static CXXConstructorDecl *CreateDeserialized(ASTContext &C, DeclID ID,
uint64_t AllocKind);
static CXXConstructorDecl *
Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
Expand Down Expand Up @@ -2822,7 +2822,7 @@ class CXXDestructorDecl : public CXXMethodDecl {
bool UsesFPIntrin, bool isInline, bool isImplicitlyDeclared,
ConstexprSpecKind ConstexprKind,
Expr *TrailingRequiresClause = nullptr);
static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID);
static CXXDestructorDecl *CreateDeserialized(ASTContext & C, DeclID ID);

void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg);

Expand Down Expand Up @@ -2881,7 +2881,7 @@ class CXXConversionDecl : public CXXMethodDecl {
bool UsesFPIntrin, bool isInline, ExplicitSpecifier ES,
ConstexprSpecKind ConstexprKind, SourceLocation EndLocation,
Expr *TrailingRequiresClause = nullptr);
static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static CXXConversionDecl *CreateDeserialized(ASTContext &C, DeclID ID);

ExplicitSpecifier getExplicitSpecifier() {
return getCanonicalDecl()->ExplicitSpec;
Expand Down Expand Up @@ -2948,7 +2948,7 @@ class LinkageSpecDecl : public Decl, public DeclContext {
SourceLocation ExternLoc,
SourceLocation LangLoc,
LinkageSpecLanguageIDs Lang, bool HasBraces);
static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static LinkageSpecDecl *CreateDeserialized(ASTContext &C, DeclID ID);

/// Return the language specified by this linkage specification.
LinkageSpecLanguageIDs getLanguage() const {
Expand Down Expand Up @@ -3096,7 +3096,7 @@ class UsingDirectiveDecl : public NamedDecl {
SourceLocation IdentLoc,
NamedDecl *Nominated,
DeclContext *CommonAncestor);
static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, DeclID ID);

SourceRange getSourceRange() const override LLVM_READONLY {
return SourceRange(UsingLoc, getLocation());
Expand Down Expand Up @@ -3157,7 +3157,7 @@ class NamespaceAliasDecl : public NamedDecl,
SourceLocation IdentLoc,
NamedDecl *Namespace);

static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, DeclID ID);

using redecl_range = redeclarable_base::redecl_range;
using redecl_iterator = redeclarable_base::redecl_iterator;
Expand Down Expand Up @@ -3254,7 +3254,7 @@ class LifetimeExtendedTemporaryDecl final
LifetimeExtendedTemporaryDecl(Temp, EDec, Mangling);
}
static LifetimeExtendedTemporaryDecl *CreateDeserialized(ASTContext &C,
unsigned ID) {
DeclID ID) {
return new (C, ID) LifetimeExtendedTemporaryDecl(EmptyShell{});
}

Expand Down Expand Up @@ -3357,7 +3357,7 @@ class UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> {
UsingShadowDecl(UsingShadow, C, DC, Loc, Name, Introducer, Target);
}

static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static UsingShadowDecl *CreateDeserialized(ASTContext &C, DeclID ID);

using redecl_range = redeclarable_base::redecl_range;
using redecl_iterator = redeclarable_base::redecl_iterator;
Expand Down Expand Up @@ -3566,7 +3566,7 @@ class UsingDecl : public BaseUsingDecl, public Mergeable<UsingDecl> {
const DeclarationNameInfo &NameInfo,
bool HasTypenameKeyword);

static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static UsingDecl *CreateDeserialized(ASTContext &C, DeclID ID);

SourceRange getSourceRange() const override LLVM_READONLY;

Expand Down Expand Up @@ -3645,7 +3645,7 @@ class ConstructorUsingShadowDecl final : public UsingShadowDecl {
UsingDecl *Using, NamedDecl *Target,
bool IsVirtual);
static ConstructorUsingShadowDecl *CreateDeserialized(ASTContext &C,
unsigned ID);
DeclID ID);

/// Override the UsingShadowDecl's getIntroducer, returning the UsingDecl that
/// introduced this.
Expand Down Expand Up @@ -3757,7 +3757,7 @@ class UsingEnumDecl : public BaseUsingDecl, public Mergeable<UsingEnumDecl> {
SourceLocation UsingL, SourceLocation EnumL,
SourceLocation NameL, TypeSourceInfo *EnumType);

static UsingEnumDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static UsingEnumDecl *CreateDeserialized(ASTContext &C, DeclID ID);

SourceRange getSourceRange() const override LLVM_READONLY;

Expand Down Expand Up @@ -3830,7 +3830,7 @@ class UsingPackDecl final
NamedDecl *InstantiatedFrom,
ArrayRef<NamedDecl *> UsingDecls);

static UsingPackDecl *CreateDeserialized(ASTContext &C, unsigned ID,
static UsingPackDecl *CreateDeserialized(ASTContext &C, DeclID ID,
unsigned NumExpansions);

SourceRange getSourceRange() const override LLVM_READONLY {
Expand Down Expand Up @@ -3924,7 +3924,7 @@ class UnresolvedUsingValueDecl : public ValueDecl,
const DeclarationNameInfo &NameInfo, SourceLocation EllipsisLoc);

static UnresolvedUsingValueDecl *
CreateDeserialized(ASTContext &C, unsigned ID);
CreateDeserialized(ASTContext &C, DeclID ID);

SourceRange getSourceRange() const override LLVM_READONLY;

Expand Down Expand Up @@ -4015,7 +4015,7 @@ class UnresolvedUsingTypenameDecl
SourceLocation EllipsisLoc);

static UnresolvedUsingTypenameDecl *
CreateDeserialized(ASTContext &C, unsigned ID);
CreateDeserialized(ASTContext &C, DeclID ID);

/// Retrieves the canonical declaration of this declaration.
UnresolvedUsingTypenameDecl *getCanonicalDecl() override {
Expand Down Expand Up @@ -4045,7 +4045,7 @@ class UnresolvedUsingIfExistsDecl final : public NamedDecl {
SourceLocation Loc,
DeclarationName Name);
static UnresolvedUsingIfExistsDecl *CreateDeserialized(ASTContext &Ctx,
unsigned ID);
DeclID ID);

static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingIfExists; }
Expand Down Expand Up @@ -4073,7 +4073,7 @@ class StaticAssertDecl : public Decl {
SourceLocation StaticAssertLoc,
Expr *AssertExpr, Expr *Message,
SourceLocation RParenLoc, bool Failed);
static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static StaticAssertDecl *CreateDeserialized(ASTContext &C, DeclID ID);

Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); }
const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); }
Expand Down Expand Up @@ -4120,7 +4120,7 @@ class BindingDecl : public ValueDecl {

static BindingDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation IdLoc, IdentifierInfo *Id);
static BindingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static BindingDecl *CreateDeserialized(ASTContext &C, DeclID ID);

/// Get the expression to which this declaration is bound. This may be null
/// in two different cases: while parsing the initializer for the
Expand Down Expand Up @@ -4189,7 +4189,7 @@ class DecompositionDecl final
QualType T, TypeSourceInfo *TInfo,
StorageClass S,
ArrayRef<BindingDecl *> Bindings);
static DecompositionDecl *CreateDeserialized(ASTContext &C, unsigned ID,
static DecompositionDecl *CreateDeserialized(ASTContext &C, DeclID ID,
unsigned NumBindings);

ArrayRef<BindingDecl *> bindings() const {
Expand Down Expand Up @@ -4246,7 +4246,7 @@ class MSPropertyDecl : public DeclaratorDecl {
SourceLocation L, DeclarationName N, QualType T,
TypeSourceInfo *TInfo, SourceLocation StartL,
IdentifierInfo *Getter, IdentifierInfo *Setter);
static MSPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static MSPropertyDecl *CreateDeserialized(ASTContext &C, DeclID ID);

static bool classof(const Decl *D) { return D->getKind() == MSProperty; }

Expand Down Expand Up @@ -4300,7 +4300,7 @@ class MSGuidDecl : public ValueDecl,
MSGuidDecl(DeclContext *DC, QualType T, Parts P);

static MSGuidDecl *Create(const ASTContext &C, QualType T, Parts P);
static MSGuidDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static MSGuidDecl *CreateDeserialized(ASTContext &C, DeclID ID);

// Only ASTContext::getMSGuidDecl and deserialization create these.
friend class ASTContext;
Expand Down Expand Up @@ -4353,7 +4353,7 @@ class UnnamedGlobalConstantDecl : public ValueDecl,
static UnnamedGlobalConstantDecl *Create(const ASTContext &C, QualType T,
const APValue &APVal);
static UnnamedGlobalConstantDecl *CreateDeserialized(ASTContext &C,
unsigned ID);
DeclID ID);

// Only ASTContext::getUnnamedGlobalConstantDecl and deserialization create
// these.
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/AST/DeclFriend.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class FriendDecl final
Create(ASTContext &C, DeclContext *DC, SourceLocation L, FriendUnion Friend_,
SourceLocation FriendL,
ArrayRef<TemplateParameterList *> FriendTypeTPLists = std::nullopt);
static FriendDecl *CreateDeserialized(ASTContext &C, unsigned ID,
static FriendDecl *CreateDeserialized(ASTContext &C, DeclID ID,
unsigned FriendTypeNumTPLists);

/// If this friend declaration names an (untemplated but possibly
Expand Down
24 changes: 12 additions & 12 deletions clang/include/clang/AST/DeclObjC.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class ObjCMethodDecl : public NamedDecl, public DeclContext {
ObjCImplementationControl impControl = ObjCImplementationControl::None,
bool HasRelatedResultType = false);

static ObjCMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static ObjCMethodDecl *CreateDeserialized(ASTContext &C, DeclID ID);

ObjCMethodDecl *getCanonicalDecl() override;
const ObjCMethodDecl *getCanonicalDecl() const {
Expand Down Expand Up @@ -614,7 +614,7 @@ class ObjCTypeParamDecl : public TypedefNameDecl {
IdentifierInfo *name,
SourceLocation colonLoc,
TypeSourceInfo *boundInfo);
static ObjCTypeParamDecl *CreateDeserialized(ASTContext &ctx, unsigned ID);
static ObjCTypeParamDecl *CreateDeserialized(ASTContext &ctx, DeclID ID);

SourceRange getSourceRange() const override LLVM_READONLY;

Expand Down Expand Up @@ -789,7 +789,7 @@ class ObjCPropertyDecl : public NamedDecl {
TypeSourceInfo *TSI,
PropertyControl propControl = None);

static ObjCPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static ObjCPropertyDecl *CreateDeserialized(ASTContext &C, DeclID ID);

SourceLocation getAtLoc() const { return AtLoc; }
void setAtLoc(SourceLocation L) { AtLoc = L; }
Expand Down Expand Up @@ -1279,7 +1279,7 @@ class ObjCInterfaceDecl : public ObjCContainerDecl
ObjCInterfaceDecl *PrevDecl,
SourceLocation ClassLoc = SourceLocation(), bool isInternal = false);

static ObjCInterfaceDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
static ObjCInterfaceDecl *CreateDeserialized(const ASTContext &C, DeclID ID);

/// Retrieve the type parameters of this class.
///
Expand Down Expand Up @@ -1969,7 +1969,7 @@ class ObjCIvarDecl : public FieldDecl {
TypeSourceInfo *TInfo, AccessControl ac,
Expr *BW = nullptr, bool synthesized = false);

static ObjCIvarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static ObjCIvarDecl *CreateDeserialized(ASTContext &C, DeclID ID);

/// Return the class interface that this ivar is logically contained
/// in; this is either the interface where the ivar was declared, or the
Expand Down Expand Up @@ -2039,7 +2039,7 @@ class ObjCAtDefsFieldDecl : public FieldDecl {
SourceLocation IdLoc, IdentifierInfo *Id,
QualType T, Expr *BW);

static ObjCAtDefsFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static ObjCAtDefsFieldDecl *CreateDeserialized(ASTContext &C, DeclID ID);

// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
Expand Down Expand Up @@ -2142,7 +2142,7 @@ class ObjCProtocolDecl : public ObjCContainerDecl,
SourceLocation atStartLoc,
ObjCProtocolDecl *PrevDecl);

static ObjCProtocolDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static ObjCProtocolDecl *CreateDeserialized(ASTContext &C, DeclID ID);

const ObjCProtocolList &getReferencedProtocols() const {
assert(hasDefinition() && "No definition available!");
Expand Down Expand Up @@ -2361,7 +2361,7 @@ class ObjCCategoryDecl : public ObjCContainerDecl {
ObjCTypeParamList *typeParamList,
SourceLocation IvarLBraceLoc = SourceLocation(),
SourceLocation IvarRBraceLoc = SourceLocation());
static ObjCCategoryDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static ObjCCategoryDecl *CreateDeserialized(ASTContext &C, DeclID ID);

ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
Expand Down Expand Up @@ -2558,7 +2558,7 @@ class ObjCCategoryImplDecl : public ObjCImplDecl {
Create(ASTContext &C, DeclContext *DC, const IdentifierInfo *Id,
ObjCInterfaceDecl *classInterface, SourceLocation nameLoc,
SourceLocation atStartLoc, SourceLocation CategoryNameLoc);
static ObjCCategoryImplDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static ObjCCategoryImplDecl *CreateDeserialized(ASTContext &C, DeclID ID);

ObjCCategoryDecl *getCategoryDecl() const;

Expand Down Expand Up @@ -2640,7 +2640,7 @@ class ObjCImplementationDecl : public ObjCImplDecl {
SourceLocation IvarLBraceLoc=SourceLocation(),
SourceLocation IvarRBraceLoc=SourceLocation());

static ObjCImplementationDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static ObjCImplementationDecl *CreateDeserialized(ASTContext &C, DeclID ID);

/// init_iterator - Iterates through the ivar initializer list.
using init_iterator = CXXCtorInitializer **;
Expand Down Expand Up @@ -2780,7 +2780,7 @@ class ObjCCompatibleAliasDecl : public NamedDecl {
ObjCInterfaceDecl* aliasedClass);

static ObjCCompatibleAliasDecl *CreateDeserialized(ASTContext &C,
unsigned ID);
DeclID ID);

const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; }
ObjCInterfaceDecl *getClassInterface() { return AliasedClass; }
Expand Down Expand Up @@ -2851,7 +2851,7 @@ class ObjCPropertyImplDecl : public Decl {
ObjCIvarDecl *ivarDecl,
SourceLocation ivarLoc);

static ObjCPropertyImplDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static ObjCPropertyImplDecl *CreateDeserialized(ASTContext &C, DeclID ID);

SourceRange getSourceRange() const override LLVM_READONLY;

Expand Down
12 changes: 6 additions & 6 deletions clang/include/clang/AST/DeclOpenMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class OMPThreadPrivateDecl final : public OMPDeclarativeDirective<Decl> {
SourceLocation L,
ArrayRef<Expr *> VL);
static OMPThreadPrivateDecl *CreateDeserialized(ASTContext &C,
unsigned ID, unsigned N);
DeclID ID, unsigned N);

typedef MutableArrayRef<Expr *>::iterator varlist_iterator;
typedef ArrayRef<const Expr *>::iterator varlist_const_iterator;
Expand Down Expand Up @@ -214,7 +214,7 @@ class OMPDeclareReductionDecl final : public ValueDecl, public DeclContext {
QualType T, OMPDeclareReductionDecl *PrevDeclInScope);
/// Create deserialized declare reduction node.
static OMPDeclareReductionDecl *CreateDeserialized(ASTContext &C,
unsigned ID);
DeclID ID);

/// Get combiner expression of the declare reduction construct.
Expr *getCombiner() { return Combiner; }
Expand Down Expand Up @@ -318,7 +318,7 @@ class OMPDeclareMapperDecl final : public OMPDeclarativeDirective<ValueDecl>,
ArrayRef<OMPClause *> Clauses,
OMPDeclareMapperDecl *PrevDeclInScope);
/// Creates deserialized declare mapper node.
static OMPDeclareMapperDecl *CreateDeserialized(ASTContext &C, unsigned ID,
static OMPDeclareMapperDecl *CreateDeserialized(ASTContext &C, DeclID ID,
unsigned N);

using clauselist_iterator = MutableArrayRef<OMPClause *>::iterator;
Expand Down Expand Up @@ -397,7 +397,7 @@ class OMPCapturedExprDecl final : public VarDecl {
IdentifierInfo *Id, QualType T,
SourceLocation StartLoc);

static OMPCapturedExprDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static OMPCapturedExprDecl *CreateDeserialized(ASTContext &C, DeclID ID);

SourceRange getSourceRange() const override LLVM_READONLY;

Expand Down Expand Up @@ -427,7 +427,7 @@ class OMPRequiresDecl final : public OMPDeclarativeDirective<Decl> {
static OMPRequiresDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation L, ArrayRef<OMPClause *> CL);
/// Create deserialized requires node.
static OMPRequiresDecl *CreateDeserialized(ASTContext &C, unsigned ID,
static OMPRequiresDecl *CreateDeserialized(ASTContext &C, DeclID ID,
unsigned N);

using clauselist_iterator = MutableArrayRef<OMPClause *>::iterator;
Expand Down Expand Up @@ -495,7 +495,7 @@ class OMPAllocateDecl final : public OMPDeclarativeDirective<Decl> {
static OMPAllocateDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation L, ArrayRef<Expr *> VL,
ArrayRef<OMPClause *> CL);
static OMPAllocateDecl *CreateDeserialized(ASTContext &C, unsigned ID,
static OMPAllocateDecl *CreateDeserialized(ASTContext &C, DeclID ID,
unsigned NVars, unsigned NClauses);

typedef MutableArrayRef<Expr *>::iterator varlist_iterator;
Expand Down
38 changes: 19 additions & 19 deletions clang/include/clang/AST/DeclTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ class RedeclarableTemplateDecl : public TemplateDecl,
///
/// The first value in the array is the number of specializations/partial
/// specializations that follow.
uint32_t *LazySpecializations = nullptr;
Decl::DeclID *LazySpecializations = nullptr;

/// The set of "injected" template arguments used within this
/// template.
Expand Down Expand Up @@ -1087,7 +1087,7 @@ class FunctionTemplateDecl : public RedeclarableTemplateDecl {
NamedDecl *Decl);

/// Create an empty function template node.
static FunctionTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static FunctionTemplateDecl *CreateDeserialized(ASTContext &C, DeclID ID);

// Implement isa/cast/dyncast support
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
Expand Down Expand Up @@ -1204,9 +1204,9 @@ class TemplateTypeParmDecl final : public TypeDecl,
bool Typename, bool ParameterPack, bool HasTypeConstraint = false,
std::optional<unsigned> NumExpanded = std::nullopt);
static TemplateTypeParmDecl *CreateDeserialized(const ASTContext &C,
unsigned ID);
DeclID ID);
static TemplateTypeParmDecl *CreateDeserialized(const ASTContext &C,
unsigned ID,
DeclID ID,
bool HasTypeConstraint);

/// Whether this template type parameter was declared with
Expand Down Expand Up @@ -1414,10 +1414,10 @@ class NonTypeTemplateParmDecl final
ArrayRef<TypeSourceInfo *> ExpandedTInfos);

static NonTypeTemplateParmDecl *CreateDeserialized(ASTContext &C,
unsigned ID,
DeclID ID,
bool HasTypeConstraint);
static NonTypeTemplateParmDecl *CreateDeserialized(ASTContext &C,
unsigned ID,
DeclID ID,
unsigned NumExpandedTypes,
bool HasTypeConstraint);

Expand Down Expand Up @@ -1632,9 +1632,9 @@ class TemplateTemplateParmDecl final
ArrayRef<TemplateParameterList *> Expansions);

static TemplateTemplateParmDecl *CreateDeserialized(ASTContext &C,
unsigned ID);
DeclID ID);
static TemplateTemplateParmDecl *CreateDeserialized(ASTContext &C,
unsigned ID,
DeclID ID,
unsigned NumExpansions);

using TemplateParmPosition::getDepth;
Expand Down Expand Up @@ -1858,7 +1858,7 @@ class ClassTemplateSpecializationDecl
ArrayRef<TemplateArgument> Args,
ClassTemplateSpecializationDecl *PrevDecl);
static ClassTemplateSpecializationDecl *
CreateDeserialized(ASTContext &C, unsigned ID);
CreateDeserialized(ASTContext &C, DeclID ID);

void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy,
bool Qualified) const override;
Expand Down Expand Up @@ -2110,7 +2110,7 @@ class ClassTemplatePartialSpecializationDecl
ClassTemplatePartialSpecializationDecl *PrevDecl);

static ClassTemplatePartialSpecializationDecl *
CreateDeserialized(ASTContext &C, unsigned ID);
CreateDeserialized(ASTContext &C, DeclID ID);

ClassTemplatePartialSpecializationDecl *getMostRecentDecl() {
return cast<ClassTemplatePartialSpecializationDecl>(
Expand Down Expand Up @@ -2306,7 +2306,7 @@ class ClassTemplateDecl : public RedeclarableTemplateDecl {
NamedDecl *Decl);

/// Create an empty class template node.
static ClassTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static ClassTemplateDecl *CreateDeserialized(ASTContext &C, DeclID ID);

/// Return the specialization with the provided arguments if it exists,
/// otherwise return the insertion point.
Expand Down Expand Up @@ -2472,7 +2472,7 @@ class FriendTemplateDecl : public Decl {
MutableArrayRef<TemplateParameterList *> Params, FriendUnion Friend,
SourceLocation FriendLoc);

static FriendTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static FriendTemplateDecl *CreateDeserialized(ASTContext &C, DeclID ID);

/// If this friend declaration names a templated type (or
/// a dependent member type of a templated type), return that
Expand Down Expand Up @@ -2573,7 +2573,7 @@ class TypeAliasTemplateDecl : public RedeclarableTemplateDecl {
NamedDecl *Decl);

/// Create an empty alias template node.
static TypeAliasTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static TypeAliasTemplateDecl *CreateDeserialized(ASTContext &C, DeclID ID);

// Implement isa/cast/dyncast support
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
Expand Down Expand Up @@ -2670,7 +2670,7 @@ class VarTemplateSpecializationDecl : public VarDecl,
TypeSourceInfo *TInfo, StorageClass S,
ArrayRef<TemplateArgument> Args);
static VarTemplateSpecializationDecl *CreateDeserialized(ASTContext &C,
unsigned ID);
DeclID ID);

void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy,
bool Qualified) const override;
Expand Down Expand Up @@ -2901,7 +2901,7 @@ class VarTemplatePartialSpecializationDecl
const TemplateArgumentListInfo &ArgInfos);

static VarTemplatePartialSpecializationDecl *CreateDeserialized(ASTContext &C,
unsigned ID);
DeclID ID);

VarTemplatePartialSpecializationDecl *getMostRecentDecl() {
return cast<VarTemplatePartialSpecializationDecl>(
Expand Down Expand Up @@ -3078,7 +3078,7 @@ class VarTemplateDecl : public RedeclarableTemplateDecl {
VarDecl *Decl);

/// Create an empty variable template node.
static VarTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static VarTemplateDecl *CreateDeserialized(ASTContext &C, DeclID ID);

/// Return the specialization with the provided arguments if it exists,
/// otherwise return the insertion point.
Expand Down Expand Up @@ -3183,7 +3183,7 @@ class ConceptDecl : public TemplateDecl, public Mergeable<ConceptDecl> {
SourceLocation L, DeclarationName Name,
TemplateParameterList *Params,
Expr *ConstraintExpr);
static ConceptDecl *CreateDeserialized(ASTContext &C, unsigned ID);
static ConceptDecl *CreateDeserialized(ASTContext &C, DeclID ID);

Expr *getConstraintExpr() const {
return ConstraintExpr;
Expand Down Expand Up @@ -3232,7 +3232,7 @@ class ImplicitConceptSpecializationDecl final
Create(const ASTContext &C, DeclContext *DC, SourceLocation SL,
ArrayRef<TemplateArgument> ConvertedArgs);
static ImplicitConceptSpecializationDecl *
CreateDeserialized(const ASTContext &C, unsigned ID,
CreateDeserialized(const ASTContext &C, DeclID ID,
unsigned NumTemplateArgs);

ArrayRef<TemplateArgument> getTemplateArguments() const {
Expand Down Expand Up @@ -3275,7 +3275,7 @@ class TemplateParamObjectDecl : public ValueDecl,
static TemplateParamObjectDecl *Create(const ASTContext &C, QualType T,
const APValue &V);
static TemplateParamObjectDecl *CreateDeserialized(ASTContext &C,
unsigned ID);
DeclID ID);

/// Only ASTContext::getTemplateParamObjectDecl and deserialization
/// create these.
Expand Down
9 changes: 3 additions & 6 deletions clang/include/clang/AST/ExprCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -3198,7 +3198,6 @@ class UnresolvedLookupExpr final
NestedNameSpecifierLoc QualifierLoc,
SourceLocation TemplateKWLoc,
const DeclarationNameInfo &NameInfo, bool RequiresADL,
bool Overloaded,
const TemplateArgumentListInfo *TemplateArgs,
UnresolvedSetIterator Begin, UnresolvedSetIterator End,
bool KnownDependent);
Expand All @@ -3218,8 +3217,9 @@ class UnresolvedLookupExpr final
static UnresolvedLookupExpr *
Create(const ASTContext &Context, CXXRecordDecl *NamingClass,
NestedNameSpecifierLoc QualifierLoc,
const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded,
UnresolvedSetIterator Begin, UnresolvedSetIterator End);
const DeclarationNameInfo &NameInfo, bool RequiresADL,
UnresolvedSetIterator Begin, UnresolvedSetIterator End,
bool KnownDependent);

// After canonicalization, there may be dependent template arguments in
// CanonicalConverted But none of Args is dependent. When any of
Expand All @@ -3240,9 +3240,6 @@ class UnresolvedLookupExpr final
/// argument-dependent lookup.
bool requiresADL() const { return UnresolvedLookupExprBits.RequiresADL; }

/// True if this lookup is overloaded.
bool isOverloaded() const { return UnresolvedLookupExprBits.Overloaded; }

/// Gets the 'naming class' (in the sense of C++0x
/// [class.access.base]p5) of the lookup. This is the scope
/// that was looked in to find these results.
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/AST/ExternalASTSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ExternalASTSource : public RefCountedBase<ExternalASTSource> {
/// passes back decl sets as VisibleDeclaration objects.
///
/// The default implementation of this method is a no-op.
virtual Decl *GetExternalDecl(uint32_t ID);
virtual Decl *GetExternalDecl(Decl::DeclID ID);

/// Resolve a selector ID into a selector.
///
Expand Down Expand Up @@ -579,7 +579,7 @@ using LazyDeclStmtPtr =

/// A lazy pointer to a declaration.
using LazyDeclPtr =
LazyOffsetPtr<Decl, uint32_t, &ExternalASTSource::GetExternalDecl>;
LazyOffsetPtr<Decl, Decl::DeclID, &ExternalASTSource::GetExternalDecl>;

/// A lazy pointer to a set of CXXCtorInitializers.
using LazyCXXCtorInitializersPtr =
Expand Down
105 changes: 105 additions & 0 deletions clang/include/clang/AST/OpenACCClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,111 @@ class OpenACCSelfClause : public OpenACCClauseWithCondition {
Expr *ConditionExpr, SourceLocation EndLoc);
};

/// Represents a clause that has one or more IntExprs. It does not own the
/// IntExprs, but provides 'children' and other accessors.
class OpenACCClauseWithIntExprs : public OpenACCClauseWithParams {
MutableArrayRef<Expr *> IntExprs;

protected:
OpenACCClauseWithIntExprs(OpenACCClauseKind K, SourceLocation BeginLoc,
SourceLocation LParenLoc, SourceLocation EndLoc)
: OpenACCClauseWithParams(K, BeginLoc, LParenLoc, EndLoc) {}

/// Used only for initialization, the leaf class can initialize this to
/// trailing storage.
void setIntExprs(MutableArrayRef<Expr *> NewIntExprs) {
assert(IntExprs.empty() && "Cannot change IntExprs list");
IntExprs = NewIntExprs;
}

/// Gets the entire list of integer expressions, but leave it to the
/// individual clauses to expose this how they'd like.
llvm::ArrayRef<Expr *> getIntExprs() const { return IntExprs; }

public:
child_range children() {
return child_range(reinterpret_cast<Stmt **>(IntExprs.begin()),
reinterpret_cast<Stmt **>(IntExprs.end()));
}

const_child_range children() const {
child_range Children =
const_cast<OpenACCClauseWithIntExprs *>(this)->children();
return const_child_range(Children.begin(), Children.end());
}
};

class OpenACCNumGangsClause final
: public OpenACCClauseWithIntExprs,
public llvm::TrailingObjects<OpenACCNumGangsClause, Expr *> {

OpenACCNumGangsClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
ArrayRef<Expr *> IntExprs, SourceLocation EndLoc)
: OpenACCClauseWithIntExprs(OpenACCClauseKind::NumGangs, BeginLoc,
LParenLoc, EndLoc) {
std::uninitialized_copy(IntExprs.begin(), IntExprs.end(),
getTrailingObjects<Expr *>());
setIntExprs(MutableArrayRef(getTrailingObjects<Expr *>(), IntExprs.size()));
}

public:
static OpenACCNumGangsClause *
Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
ArrayRef<Expr *> IntExprs, SourceLocation EndLoc);

llvm::ArrayRef<Expr *> getIntExprs() {
return OpenACCClauseWithIntExprs::getIntExprs();
}

llvm::ArrayRef<Expr *> getIntExprs() const {
return OpenACCClauseWithIntExprs::getIntExprs();
}
};

/// Represents one of a handful of clauses that have a single integer
/// expression.
class OpenACCClauseWithSingleIntExpr : public OpenACCClauseWithIntExprs {
Expr *IntExpr;

protected:
OpenACCClauseWithSingleIntExpr(OpenACCClauseKind K, SourceLocation BeginLoc,
SourceLocation LParenLoc, Expr *IntExpr,
SourceLocation EndLoc)
: OpenACCClauseWithIntExprs(K, BeginLoc, LParenLoc, EndLoc),
IntExpr(IntExpr) {
setIntExprs(MutableArrayRef<Expr *>{&this->IntExpr, 1});
}

public:
bool hasIntExpr() const { return !getIntExprs().empty(); }
const Expr *getIntExpr() const {
return hasIntExpr() ? getIntExprs()[0] : nullptr;
}

Expr *getIntExpr() { return hasIntExpr() ? getIntExprs()[0] : nullptr; };
};

class OpenACCNumWorkersClause : public OpenACCClauseWithSingleIntExpr {
OpenACCNumWorkersClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
Expr *IntExpr, SourceLocation EndLoc);

public:
static OpenACCNumWorkersClause *Create(const ASTContext &C,
SourceLocation BeginLoc,
SourceLocation LParenLoc,
Expr *IntExpr, SourceLocation EndLoc);
};

class OpenACCVectorLengthClause : public OpenACCClauseWithSingleIntExpr {
OpenACCVectorLengthClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
Expr *IntExpr, SourceLocation EndLoc);

public:
static OpenACCVectorLengthClause *
Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
Expr *IntExpr, SourceLocation EndLoc);
};

template <class Impl> class OpenACCClauseVisitor {
Impl &getDerived() { return static_cast<Impl &>(*this); }

Expand Down
5 changes: 0 additions & 5 deletions clang/include/clang/AST/Stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1067,11 +1067,6 @@ class alignas(void *) Stmt {
/// argument-dependent lookup if this is the operand of a function call.
LLVM_PREFERRED_TYPE(bool)
unsigned RequiresADL : 1;

/// True if these lookup results are overloaded. This is pretty trivially
/// rederivable if we urgently need to kill this field.
LLVM_PREFERRED_TYPE(bool)
unsigned Overloaded : 1;
};
static_assert(sizeof(UnresolvedLookupExprBitfields) <= 4,
"UnresolvedLookupExprBitfields must be <= than 4 bytes to"
Expand Down
Loading