[clang] [llvm] Use TimeTraceProfilerEntry for Source span (PR #83961)
Takuto Ikuta via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 4 21:41:31 PST 2024
https://github.com/atetubou created https://github.com/llvm/llvm-project/pull/83961
This fixes incorrect trace for https://github.com/llvm/llvm-project/issues/56554.
https://github.com/llvm/llvm-project/pull/83778 is preparing PR.
>From 9a4911ee0732abbe770b98396e166a4d95bc0c95 Mon Sep 17 00:00:00 2001
From: Takuto Ikuta <tikuta at google.com>
Date: Mon, 4 Mar 2024 19:12:31 +0900
Subject: [PATCH 1/2] Expose TimeTraceProfiler for overlapping spans
---
llvm/include/llvm/Support/TimeProfiler.h | 22 ++++++---
llvm/lib/Support/TimeProfiler.cpp | 63 ++++++++++++++----------
2 files changed, 53 insertions(+), 32 deletions(-)
diff --git a/llvm/include/llvm/Support/TimeProfiler.h b/llvm/include/llvm/Support/TimeProfiler.h
index 454a65f70231f4..941af7e3126c11 100644
--- a/llvm/include/llvm/Support/TimeProfiler.h
+++ b/llvm/include/llvm/Support/TimeProfiler.h
@@ -86,6 +86,8 @@ class raw_pwrite_stream;
struct TimeTraceProfiler;
TimeTraceProfiler *getTimeTraceProfilerInstance();
+struct TimeTraceProfilerEntry;
+
/// Initialize the time trace profiler.
/// This sets up the global \p TimeTraceProfilerInstance
/// variable to be the profiler instance.
@@ -120,12 +122,15 @@ Error timeTraceProfilerWrite(StringRef PreferredFileName,
/// Profiler copies the string data, so the pointers can be given into
/// temporaries. Time sections can be hierarchical; every Begin must have a
/// matching End pair but they can nest.
-void timeTraceProfilerBegin(StringRef Name, StringRef Detail);
-void timeTraceProfilerBegin(StringRef Name,
- llvm::function_ref<std::string()> Detail);
+TimeTraceProfilerEntry *timeTraceProfilerBegin(StringRef Name,
+ StringRef Detail);
+TimeTraceProfilerEntry *
+timeTraceProfilerBegin(StringRef Name,
+ llvm::function_ref<std::string()> Detail);
/// Manually end the last time section.
void timeTraceProfilerEnd();
+void timeTraceProfilerEnd(TimeTraceProfilerEntry *E);
/// The TimeTraceScope is a helper class to call the begin and end functions
/// of the time trace profiler. When the object is constructed, it begins
@@ -141,20 +146,23 @@ struct TimeTraceScope {
TimeTraceScope(StringRef Name) {
if (getTimeTraceProfilerInstance() != nullptr)
- timeTraceProfilerBegin(Name, StringRef(""));
+ Entry = timeTraceProfilerBegin(Name, StringRef(""));
}
TimeTraceScope(StringRef Name, StringRef Detail) {
if (getTimeTraceProfilerInstance() != nullptr)
- timeTraceProfilerBegin(Name, Detail);
+ Entry = timeTraceProfilerBegin(Name, Detail);
}
TimeTraceScope(StringRef Name, llvm::function_ref<std::string()> Detail) {
if (getTimeTraceProfilerInstance() != nullptr)
- timeTraceProfilerBegin(Name, Detail);
+ Entry = timeTraceProfilerBegin(Name, Detail);
}
~TimeTraceScope() {
if (getTimeTraceProfilerInstance() != nullptr)
- timeTraceProfilerEnd();
+ timeTraceProfilerEnd(Entry);
}
+
+private:
+ TimeTraceProfilerEntry *Entry = nullptr;
};
} // end namespace llvm
diff --git a/llvm/lib/Support/TimeProfiler.cpp b/llvm/lib/Support/TimeProfiler.cpp
index 4d625b3eb5b170..b195214cb52960 100644
--- a/llvm/lib/Support/TimeProfiler.cpp
+++ b/llvm/lib/Support/TimeProfiler.cpp
@@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/TimeProfiler.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/STLFunctionalExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/JSON.h"
@@ -20,6 +21,7 @@
#include <algorithm>
#include <cassert>
#include <chrono>
+#include <memory>
#include <mutex>
#include <string>
#include <vector>
@@ -64,8 +66,10 @@ using CountAndDurationType = std::pair<size_t, DurationType>;
using NameAndCountAndDurationType =
std::pair<std::string, CountAndDurationType>;
+} // anonymous namespace
+
/// Represents an open or completed time section entry to be captured.
-struct TimeTraceProfilerEntry {
+struct llvm::TimeTraceProfilerEntry {
const TimePointType Start;
TimePointType End;
const std::string Name;
@@ -92,8 +96,6 @@ struct TimeTraceProfilerEntry {
}
};
-} // anonymous namespace
-
struct llvm::TimeTraceProfiler {
TimeTraceProfiler(unsigned TimeTraceGranularity = 0, StringRef ProcName = "")
: BeginningOfTime(system_clock::now()), StartTime(ClockType::now()),
@@ -102,23 +104,22 @@ struct llvm::TimeTraceProfiler {
llvm::get_thread_name(ThreadName);
}
- void begin(std::string Name, llvm::function_ref<std::string()> Detail) {
- Stack.emplace_back(ClockType::now(), TimePointType(), std::move(Name),
- Detail());
+ TimeTraceProfilerEntry *begin(std::string Name,
+ llvm::function_ref<std::string()> Detail) {
+ Stack.emplace_back(std::make_unique<TimeTraceProfilerEntry>(
+ ClockType::now(), TimePointType(), std::move(Name), Detail()));
+ return Stack.back().get();
}
void end() {
+ TimeTraceProfilerEntry *E = Stack.back().get();
+ end(*E);
+ }
+
+ void end(TimeTraceProfilerEntry &E) {
assert(!Stack.empty() && "Must call begin() first");
- TimeTraceProfilerEntry &E = Stack.back();
E.End = ClockType::now();
- // Check that end times monotonically increase.
- assert((Entries.empty() ||
- (E.getFlameGraphStartUs(StartTime) + E.getFlameGraphDurUs() >=
- Entries.back().getFlameGraphStartUs(StartTime) +
- Entries.back().getFlameGraphDurUs())) &&
- "TimeProfiler scope ended earlier than previous scope");
-
// Calculate duration at full precision for overall counts.
DurationType Duration = E.End - E.Start;
@@ -132,15 +133,18 @@ struct llvm::TimeTraceProfiler {
// happens to be the ones that don't have any currently open entries above
// itself.
if (llvm::none_of(llvm::drop_begin(llvm::reverse(Stack)),
- [&](const TimeTraceProfilerEntry &Val) {
- return Val.Name == E.Name;
+ [&](const std::unique_ptr<TimeTraceProfilerEntry> &Val) {
+ return Val->Name == E.Name;
})) {
auto &CountAndTotal = CountAndTotalPerName[E.Name];
CountAndTotal.first++;
CountAndTotal.second += Duration;
- }
+ };
- Stack.pop_back();
+ llvm::erase_if(Stack,
+ [&](const std::unique_ptr<TimeTraceProfilerEntry> &Val) {
+ return Val.get() == &E;
+ });
}
// Write events from this TimeTraceProfilerInstance and
@@ -269,7 +273,7 @@ struct llvm::TimeTraceProfiler {
J.objectEnd();
}
- SmallVector<TimeTraceProfilerEntry, 16> Stack;
+ SmallVector<std::unique_ptr<TimeTraceProfilerEntry>, 16> Stack;
SmallVector<TimeTraceProfilerEntry, 128> Entries;
StringMap<CountAndDurationType> CountAndTotalPerName;
// System clock time when the session was begun.
@@ -341,19 +345,28 @@ Error llvm::timeTraceProfilerWrite(StringRef PreferredFileName,
return Error::success();
}
-void llvm::timeTraceProfilerBegin(StringRef Name, StringRef Detail) {
+TimeTraceProfilerEntry *llvm::timeTraceProfilerBegin(StringRef Name,
+ StringRef Detail) {
if (TimeTraceProfilerInstance != nullptr)
- TimeTraceProfilerInstance->begin(std::string(Name),
- [&]() { return std::string(Detail); });
+ return TimeTraceProfilerInstance->begin(
+ std::string(Name), [&]() { return std::string(Detail); });
+ return nullptr;
}
-void llvm::timeTraceProfilerBegin(StringRef Name,
- llvm::function_ref<std::string()> Detail) {
+TimeTraceProfilerEntry *
+llvm::timeTraceProfilerBegin(StringRef Name,
+ llvm::function_ref<std::string()> Detail) {
if (TimeTraceProfilerInstance != nullptr)
- TimeTraceProfilerInstance->begin(std::string(Name), Detail);
+ return TimeTraceProfilerInstance->begin(std::string(Name), Detail);
+ return nullptr;
}
void llvm::timeTraceProfilerEnd() {
if (TimeTraceProfilerInstance != nullptr)
TimeTraceProfilerInstance->end();
}
+
+void llvm::timeTraceProfilerEnd(TimeTraceProfilerEntry *E) {
+ if (TimeTraceProfilerInstance != nullptr)
+ TimeTraceProfilerInstance->end(*E);
+}
>From cdc771f7cc9ac9ac0abe186885ccb7f5cb202db2 Mon Sep 17 00:00:00 2001
From: Takuto Ikuta <tikuta at google.com>
Date: Mon, 4 Mar 2024 17:02:05 +0900
Subject: [PATCH 2/2] Use TimeTraceProfilerEntry for Source span
---
clang/lib/Sema/Sema.cpp | 233 +++++++++++++++++++++-------------------
1 file changed, 124 insertions(+), 109 deletions(-)
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index cfb653e665ea03..434a0a4ce30038 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -135,6 +135,7 @@ namespace sema {
class SemaPPCallbacks : public PPCallbacks {
Sema *S = nullptr;
llvm::SmallVector<SourceLocation, 8> IncludeStack;
+ llvm::SmallVector<llvm::TimeTraceProfilerEntry *, 8> ProfilerStack;
public:
void set(Sema &S) { this->S = &S; }
@@ -153,8 +154,8 @@ class SemaPPCallbacks : public PPCallbacks {
if (IncludeLoc.isValid()) {
if (llvm::timeTraceProfilerEnabled()) {
OptionalFileEntryRef FE = SM.getFileEntryRefForID(SM.getFileID(Loc));
- llvm::timeTraceProfilerBegin("Source", FE ? FE->getName()
- : StringRef("<unknown>"));
+ ProfilerStack.push_back(llvm::timeTraceProfilerBegin(
+ "Source", FE ? FE->getName() : StringRef("<unknown>")));
}
IncludeStack.push_back(IncludeLoc);
@@ -166,8 +167,9 @@ class SemaPPCallbacks : public PPCallbacks {
}
case ExitFile:
if (!IncludeStack.empty()) {
- if (llvm::timeTraceProfilerEnabled())
- llvm::timeTraceProfilerEnd();
+ if (llvm::timeTraceProfilerEnabled()) {
+ llvm::timeTraceProfilerEnd(ProfilerStack.pop_back_val());
+ }
S->DiagnoseNonDefaultPragmaAlignPack(
Sema::PragmaAlignPackDiagnoseKind::ChangedStateAtExit,
@@ -269,8 +271,8 @@ void Sema::Initialize() {
SC->InitializeSema(*this);
// Tell the external Sema source about this Sema object.
- if (ExternalSemaSource *ExternalSema
- = dyn_cast_or_null<ExternalSemaSource>(Context.getExternalSource()))
+ if (ExternalSemaSource *ExternalSema =
+ dyn_cast_or_null<ExternalSemaSource>(Context.getExternalSource()))
ExternalSema->InitializeSema(*this);
// This needs to happen after ExternalSemaSource::InitializeSema(this) or we
@@ -295,7 +297,6 @@ void Sema::Initialize() {
PushOnScopeChains(Context.getUInt128Decl(), TUScope);
}
-
// Initialize predefined Objective-C types:
if (getLangOpts().ObjC) {
// If 'SEL' does not yet refer to any declarations, make it refer to the
@@ -361,7 +362,6 @@ void Sema::Initialize() {
// 32-bit integer and OpenCLC v2.0, s6.1.1 int is always 32-bit wide.
addImplicitTypedef("atomic_flag", Context.getAtomicType(Context.IntTy));
-
// OpenCL v2.0 s6.13.11.6:
// - The atomic_long and atomic_ulong types are supported if the
// cl_khr_int64_base_atomics and cl_khr_int64_extended_atomics
@@ -410,7 +410,6 @@ void Sema::Initialize() {
addImplicitTypedef("atomic_long", AtomicLongT);
addImplicitTypedef("atomic_ulong", AtomicULongT);
-
if (Context.getTypeSize(Context.getSizeType()) == 64) {
AddPointerSizeDependentTypes();
}
@@ -425,17 +424,17 @@ void Sema::Initialize() {
}
if (Context.getTargetInfo().hasAArch64SVETypes()) {
-#define SVE_TYPE(Name, Id, SingletonId) \
- addImplicitTypedef(Name, Context.SingletonId);
+#define SVE_TYPE(Name, Id, SingletonId) \
+ addImplicitTypedef(Name, Context.SingletonId);
#include "clang/Basic/AArch64SVEACLETypes.def"
}
if (Context.getTargetInfo().getTriple().isPPC64()) {
-#define PPC_VECTOR_MMA_TYPE(Name, Id, Size) \
- addImplicitTypedef(#Name, Context.Id##Ty);
+#define PPC_VECTOR_MMA_TYPE(Name, Id, Size) \
+ addImplicitTypedef(#Name, Context.Id##Ty);
#include "clang/Basic/PPCTypes.def"
-#define PPC_VECTOR_VSX_TYPE(Name, Id, Size) \
- addImplicitTypedef(#Name, Context.Id##Ty);
+#define PPC_VECTOR_VSX_TYPE(Name, Id, Size) \
+ addImplicitTypedef(#Name, Context.Id##Ty);
#include "clang/Basic/PPCTypes.def"
}
@@ -467,7 +466,8 @@ Sema::~Sema() {
assert(InstantiatingSpecializations.empty() &&
"failed to clean up an InstantiatingTemplate?");
- if (VisContext) FreeVisContext();
+ if (VisContext)
+ FreeVisContext();
// Kill all the active scopes.
for (sema::FunctionScopeInfo *FSI : FunctionScopes)
@@ -478,8 +478,8 @@ Sema::~Sema() {
SC->ForgetSema();
// Detach from the external Sema source.
- if (ExternalSemaSource *ExternalSema
- = dyn_cast_or_null<ExternalSemaSource>(Context.getExternalSource()))
+ if (ExternalSemaSource *ExternalSema =
+ dyn_cast_or_null<ExternalSemaSource>(Context.getExternalSource()))
ExternalSema->ForgetSema();
// Delete cached satisfactions.
@@ -517,11 +517,12 @@ void Sema::runWithSufficientStackSpace(SourceLocation Loc,
/// context. If we're still in a system header, and we can plausibly
/// make the relevant declaration unavailable instead of erroring, do
/// so and return true.
-bool Sema::makeUnavailableInSystemHeader(SourceLocation loc,
- UnavailableAttr::ImplicitReason reason) {
+bool Sema::makeUnavailableInSystemHeader(
+ SourceLocation loc, UnavailableAttr::ImplicitReason reason) {
// If we're not in a function, it's an error.
FunctionDecl *fn = dyn_cast<FunctionDecl>(CurContext);
- if (!fn) return false;
+ if (!fn)
+ return false;
// If we're in template instantiation, it's an error.
if (inTemplateInstantiation())
@@ -532,7 +533,8 @@ bool Sema::makeUnavailableInSystemHeader(SourceLocation loc,
return false;
// If the function is already unavailable, it's not an error.
- if (fn->hasAttr<UnavailableAttr>()) return true;
+ if (fn->hasAttr<UnavailableAttr>())
+ return true;
fn->addAttr(UnavailableAttr::CreateImplicit(Context, "", reason, loc));
return true;
@@ -542,8 +544,8 @@ ASTMutationListener *Sema::getASTMutationListener() const {
return getASTConsumer().GetASTMutationListener();
}
-///Registers an external source. If an external source already exists,
-/// creates a multiplex external source and appends to it.
+/// Registers an external source. If an external source already exists,
+/// creates a multiplex external source and appends to it.
///
///\param[in] E - A non-null external sema source.
///
@@ -633,8 +635,8 @@ void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E) {
/// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
/// If there is already an implicit cast, merge into the existing one.
/// The result is of the given category.
-ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty,
- CastKind Kind, ExprValueKind VK,
+ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty, CastKind Kind,
+ ExprValueKind VK,
const CXXCastPath *BasePath,
CheckedConversionKind CCK) {
#ifndef NDEBUG
@@ -716,16 +718,26 @@ ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty,
/// to the conversion from scalar type ScalarTy to the Boolean type.
CastKind Sema::ScalarTypeToBooleanCastKind(QualType ScalarTy) {
switch (ScalarTy->getScalarTypeKind()) {
- case Type::STK_Bool: return CK_NoOp;
- case Type::STK_CPointer: return CK_PointerToBoolean;
- case Type::STK_BlockPointer: return CK_PointerToBoolean;
- case Type::STK_ObjCObjectPointer: return CK_PointerToBoolean;
- case Type::STK_MemberPointer: return CK_MemberPointerToBoolean;
- case Type::STK_Integral: return CK_IntegralToBoolean;
- case Type::STK_Floating: return CK_FloatingToBoolean;
- case Type::STK_IntegralComplex: return CK_IntegralComplexToBoolean;
- case Type::STK_FloatingComplex: return CK_FloatingComplexToBoolean;
- case Type::STK_FixedPoint: return CK_FixedPointToBoolean;
+ case Type::STK_Bool:
+ return CK_NoOp;
+ case Type::STK_CPointer:
+ return CK_PointerToBoolean;
+ case Type::STK_BlockPointer:
+ return CK_PointerToBoolean;
+ case Type::STK_ObjCObjectPointer:
+ return CK_PointerToBoolean;
+ case Type::STK_MemberPointer:
+ return CK_MemberPointerToBoolean;
+ case Type::STK_Integral:
+ return CK_IntegralToBoolean;
+ case Type::STK_Floating:
+ return CK_FloatingToBoolean;
+ case Type::STK_IntegralComplex:
+ return CK_IntegralComplexToBoolean;
+ case Type::STK_FloatingComplex:
+ return CK_FloatingComplexToBoolean;
+ case Type::STK_FixedPoint:
+ return CK_FixedPointToBoolean;
}
llvm_unreachable("unknown scalar type kind");
}
@@ -812,15 +824,17 @@ bool Sema::isExternalWithNoLinkageType(const ValueDecl *VD) const {
/// Obtains a sorted list of functions and variables that are undefined but
/// ODR-used.
void Sema::getUndefinedButUsed(
- SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> > &Undefined) {
+ SmallVectorImpl<std::pair<NamedDecl *, SourceLocation>> &Undefined) {
for (const auto &UndefinedUse : UndefinedButUsed) {
NamedDecl *ND = UndefinedUse.first;
// Ignore attributes that have become invalid.
- if (ND->isInvalidDecl()) continue;
+ if (ND->isInvalidDecl())
+ continue;
// __attribute__((weakref)) is basically a definition.
- if (ND->hasAttr<WeakRefAttr>()) continue;
+ if (ND->hasAttr<WeakRefAttr>())
+ continue;
if (isa<CXXDeductionGuideDecl>(ND))
continue;
@@ -835,8 +849,7 @@ void Sema::getUndefinedButUsed(
if (const auto *FD = dyn_cast<FunctionDecl>(ND)) {
if (FD->isDefined())
continue;
- if (FD->isExternallyVisible() &&
- !isExternalWithNoLinkageType(FD) &&
+ if (FD->isExternallyVisible() && !isExternalWithNoLinkageType(FD) &&
!FD->getMostRecentDecl()->isInlined() &&
!FD->hasAttr<ExcludeFromExplicitInstantiationAttr>())
continue;
@@ -846,8 +859,7 @@ void Sema::getUndefinedButUsed(
const auto *VD = cast<VarDecl>(ND);
if (VD->hasDefinition() != VarDecl::DeclarationOnly)
continue;
- if (VD->isExternallyVisible() &&
- !isExternalWithNoLinkageType(VD) &&
+ if (VD->isExternallyVisible() && !isExternalWithNoLinkageType(VD) &&
!VD->getMostRecentDecl()->isInline() &&
!VD->hasAttr<ExcludeFromExplicitInstantiationAttr>())
continue;
@@ -865,13 +877,15 @@ void Sema::getUndefinedButUsed(
/// checkUndefinedButUsed - Check for undefined objects with internal linkage
/// or that are inline.
static void checkUndefinedButUsed(Sema &S) {
- if (S.UndefinedButUsed.empty()) return;
+ if (S.UndefinedButUsed.empty())
+ return;
// Collect all the still-undefined entities with internal linkage.
SmallVector<std::pair<NamedDecl *, SourceLocation>, 16> Undefined;
S.getUndefinedButUsed(Undefined);
S.UndefinedButUsed.clear();
- if (Undefined.empty()) return;
+ if (Undefined.empty())
+ return;
for (const auto &Undef : Undefined) {
ValueDecl *VD = cast<ValueDecl>(Undef.first);
@@ -890,7 +904,7 @@ static void checkUndefinedButUsed(Sema &S) {
S.Diag(VD->getLocation(), isExternallyVisible(VD->getType()->getLinkage())
? diag::ext_undefined_internal_type
: diag::err_undefined_internal_type)
- << isa<VarDecl>(VD) << VD;
+ << isa<VarDecl>(VD) << VD;
} else if (!VD->isExternallyVisible()) {
// FIXME: We can promote this to an error. The function or variable can't
// be defined anywhere else, so the program must necessarily violate the
@@ -936,8 +950,7 @@ void Sema::LoadExternalWeakUndeclaredIdentifiers() {
(void)WeakUndeclaredIdentifiers[WeakID.first].insert(WeakID.second);
}
-
-typedef llvm::DenseMap<const CXXRecordDecl*, bool> RecordCompleteMap;
+typedef llvm::DenseMap<const CXXRecordDecl *, bool> RecordCompleteMap;
/// Returns true, if all methods and nested classes of the given
/// CXXRecordDecl are defined in this translation unit.
@@ -952,8 +965,7 @@ static bool MethodsAndNestedClassesComplete(const CXXRecordDecl *RD,
if (!RD->isCompleteDefinition())
return false;
bool Complete = true;
- for (DeclContext::decl_iterator I = RD->decls_begin(),
- E = RD->decls_end();
+ for (DeclContext::decl_iterator I = RD->decls_begin(), E = RD->decls_end();
I != E && Complete; ++I) {
if (const CXXMethodDecl *M = dyn_cast<CXXMethodDecl>(*I))
Complete = M->isDefined() || M->isDefaulted() ||
@@ -964,13 +976,13 @@ static bool MethodsAndNestedClassesComplete(const CXXRecordDecl *RD,
// performed semantic analysis on it yet, so we cannot know if the type
// can be considered complete.
Complete = !F->getTemplatedDecl()->isLateTemplateParsed() &&
- F->getTemplatedDecl()->isDefined();
+ F->getTemplatedDecl()->isDefined();
else if (const CXXRecordDecl *R = dyn_cast<CXXRecordDecl>(*I)) {
if (R->isInjectedClassName())
continue;
if (R->hasDefinition())
- Complete = MethodsAndNestedClassesComplete(R->getDefinition(),
- MNCComplete);
+ Complete =
+ MethodsAndNestedClassesComplete(R->getDefinition(), MNCComplete);
else
Complete = false;
}
@@ -1006,7 +1018,7 @@ static bool IsRecordFullyDefined(const CXXRecordDecl *RD,
} else {
// Friend functions are available through the NamedDecl of FriendDecl.
if (const FunctionDecl *FD =
- dyn_cast<FunctionDecl>((*I)->getFriendDecl()))
+ dyn_cast<FunctionDecl>((*I)->getFriendDecl()))
Complete = FD->isDefined();
else
// This is a template friend, give up.
@@ -1079,8 +1091,8 @@ void Sema::ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind) {
for (auto PII : Pending)
if (auto Func = dyn_cast<FunctionDecl>(PII.first))
Func->setInstantiationIsPending(true);
- PendingInstantiations.insert(PendingInstantiations.begin(),
- Pending.begin(), Pending.end());
+ PendingInstantiations.insert(PendingInstantiations.begin(), Pending.begin(),
+ Pending.end());
}
{
@@ -1108,8 +1120,8 @@ void Sema::ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind) {
/// translation unit when EOF is reached and all but the top-level scope is
/// popped.
void Sema::ActOnEndOfTranslationUnit() {
- assert(DelayedDiagnostics.getCurrentPool() == nullptr
- && "reached end of translation unit with a pool attached?");
+ assert(DelayedDiagnostics.getCurrentPool() == nullptr &&
+ "reached end of translation unit with a pool attached?");
// If code completion is enabled, don't perform any end-of-translation-unit
// work.
@@ -1327,8 +1339,8 @@ void Sema::ActOnEndOfTranslationUnit() {
if (!VD || VD->isInvalidDecl() || !Seen.insert(VD).second)
continue;
- if (const IncompleteArrayType *ArrayT
- = Context.getAsIncompleteArrayType(VD->getType())) {
+ if (const IncompleteArrayType *ArrayT =
+ Context.getAsIncompleteArrayType(VD->getType())) {
// Set the length of the array to 1 (C99 6.9.2p5).
Diag(VD->getLocation(), diag::warn_tentative_incomplete_array);
llvm::APInt One(Context.getTypeSize(Context.getSizeType()), true);
@@ -1385,7 +1397,7 @@ void Sema::ActOnEndOfTranslationUnit() {
if (FD->getStorageClass() == SC_Static &&
!FD->isInlineSpecified() &&
!SourceMgr.isInMainFile(
- SourceMgr.getExpansionLoc(FD->getLocation())))
+ SourceMgr.getExpansionLoc(FD->getLocation())))
Diag(DiagD->getLocation(),
diag::warn_unneeded_static_internal_decl)
<< DiagD << DiagRange;
@@ -1446,7 +1458,7 @@ void Sema::ActOnEndOfTranslationUnit() {
if (RD && !RD->isUnion() &&
IsRecordFullyDefined(RD, RecordsComplete, MNCComplete)) {
Diag(D->getLocation(), diag::warn_unused_private_field)
- << D->getDeclName();
+ << D->getDeclName();
}
}
}
@@ -1474,7 +1486,6 @@ void Sema::ActOnEndOfTranslationUnit() {
TUScope = nullptr;
}
-
//===----------------------------------------------------------------------===//
// Helper functions.
//===----------------------------------------------------------------------===//
@@ -1490,7 +1501,8 @@ DeclContext *Sema::getFunctionLevelDeclContext(bool AllowLambda) const {
cast<CXXMethodDecl>(DC)->getOverloadedOperator() == OO_Call &&
cast<CXXRecordDecl>(DC->getParent())->isLambda()) {
DC = DC->getParent()->getParent();
- } else break;
+ } else
+ break;
}
return DC;
@@ -1533,8 +1545,8 @@ void Sema::EmitCurrentDiagnostic(unsigned DiagID) {
// issue I am not seeing yet), then there should at least be a clarifying
// comment somewhere.
if (std::optional<TemplateDeductionInfo *> Info = isSFINAEContext()) {
- switch (DiagnosticIDs::getDiagnosticSFINAEResponse(
- Diags.getCurrentDiagID())) {
+ switch (
+ DiagnosticIDs::getDiagnosticSFINAEResponse(Diags.getCurrentDiagID())) {
case DiagnosticIDs::SFINAE_Report:
// We'll report the diagnostic below.
break;
@@ -1548,8 +1560,9 @@ void Sema::EmitCurrentDiagnostic(unsigned DiagID) {
// template-deduction information.
if (*Info && !(*Info)->hasSFINAEDiagnostic()) {
Diagnostic DiagInfo(&Diags);
- (*Info)->addSFINAEDiagnostic(DiagInfo.getLocation(),
- PartialDiagnostic(DiagInfo, Context.getDiagAllocator()));
+ (*Info)->addSFINAEDiagnostic(
+ DiagInfo.getLocation(),
+ PartialDiagnostic(DiagInfo, Context.getDiagAllocator()));
}
Diags.setLastDiagnosticIgnored(true);
@@ -1573,8 +1586,9 @@ void Sema::EmitCurrentDiagnostic(unsigned DiagID) {
// template-deduction information.
if (*Info && !(*Info)->hasSFINAEDiagnostic()) {
Diagnostic DiagInfo(&Diags);
- (*Info)->addSFINAEDiagnostic(DiagInfo.getLocation(),
- PartialDiagnostic(DiagInfo, Context.getDiagAllocator()));
+ (*Info)->addSFINAEDiagnostic(
+ DiagInfo.getLocation(),
+ PartialDiagnostic(DiagInfo, Context.getDiagAllocator()));
}
Diags.setLastDiagnosticIgnored(true);
@@ -1595,8 +1609,9 @@ void Sema::EmitCurrentDiagnostic(unsigned DiagID) {
// template-deduction information;
if (*Info) {
Diagnostic DiagInfo(&Diags);
- (*Info)->addSuppressedDiagnostic(DiagInfo.getLocation(),
- PartialDiagnostic(DiagInfo, Context.getDiagAllocator()));
+ (*Info)->addSuppressedDiagnostic(
+ DiagInfo.getLocation(),
+ PartialDiagnostic(DiagInfo, Context.getDiagAllocator()));
}
// Suppress this diagnostic.
@@ -1733,8 +1748,7 @@ class DeferredDiagnosticsEmitter
}
void checkVar(VarDecl *VD) {
- assert(VD->isFileVarDecl() &&
- "Should only check file-scope variables");
+ assert(VD->isFileVarDecl() && "Should only check file-scope variables");
if (auto *Init = VD->getInit()) {
auto DevTy = OMPDeclareTargetDeclAttr::getDeviceType(VD);
bool IsDev = DevTy && (*DevTy == OMPDeclareTargetDeclAttr::DT_NoHost ||
@@ -2106,7 +2120,8 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
/// expansion loc.
bool Sema::findMacroSpelling(SourceLocation &locref, StringRef name) {
SourceLocation loc = locref;
- if (!loc.isMacroID()) return false;
+ if (!loc.isMacroID())
+ return false;
// There's no good way right now to look at the intermediate
// expansions, so just jump to the expansion location.
@@ -2164,8 +2179,8 @@ void Sema::PushFunctionScope() {
}
void Sema::PushBlockScope(Scope *BlockScope, BlockDecl *Block) {
- FunctionScopes.push_back(new BlockScopeInfo(getDiagnostics(),
- BlockScope, Block));
+ FunctionScopes.push_back(
+ new BlockScopeInfo(getDiagnostics(), BlockScope, Block));
CapturingFunctionScopes++;
}
@@ -2242,10 +2257,9 @@ static void markEscapingByrefs(const FunctionScopeInfo &FSI, Sema &S) {
QualType CapType = BC.getVariable()->getType();
if (CapType.hasNonTrivialToPrimitiveDestructCUnion() ||
CapType.hasNonTrivialToPrimitiveCopyCUnion())
- S.checkNonTrivialCUnion(BC.getVariable()->getType(),
- BD->getCaretLocation(),
- Sema::NTCUC_BlockCapture,
- Sema::NTCUK_Destruct|Sema::NTCUK_Copy);
+ S.checkNonTrivialCUnion(
+ BC.getVariable()->getType(), BD->getCaretLocation(),
+ Sema::NTCUC_BlockCapture, Sema::NTCUK_Destruct | Sema::NTCUK_Copy);
}
}
@@ -2292,8 +2306,8 @@ Sema::PopFunctionScopeInfo(const AnalysisBasedWarnings::Policy *WP,
return Scope;
}
-void Sema::PoppedFunctionScopeDeleter::
-operator()(sema::FunctionScopeInfo *Scope) const {
+void Sema::PoppedFunctionScopeDeleter::operator()(
+ sema::FunctionScopeInfo *Scope) const {
if (!Scope->isPlainFunction())
Self->CapturingFunctionScopes--;
// Stash the function scope for later reuse if it's for a normal function.
@@ -2346,8 +2360,7 @@ BlockScopeInfo *Sema::getCurBlock() {
return nullptr;
auto CurBSI = dyn_cast<BlockScopeInfo>(FunctionScopes.back());
- if (CurBSI && CurBSI->TheDecl &&
- !CurBSI->TheDecl->Encloses(CurContext)) {
+ if (CurBSI && CurBSI->TheDecl && !CurBSI->TheDecl->Encloses(CurContext)) {
// We have switched contexts due to template instantiation.
assert(!CodeSynthesisContexts.empty());
return nullptr;
@@ -2411,14 +2424,14 @@ LambdaScopeInfo *Sema::getCurLambda(bool IgnoreNonLambdaCapturingScope) {
// We have a generic lambda if we parsed auto parameters, or we have
// an associated template parameter list.
LambdaScopeInfo *Sema::getCurGenericLambda() {
- if (LambdaScopeInfo *LSI = getCurLambda()) {
- return (LSI->TemplateParams.size() ||
- LSI->GLTemplateParameterList) ? LSI : nullptr;
+ if (LambdaScopeInfo *LSI = getCurLambda()) {
+ return (LSI->TemplateParams.size() || LSI->GLTemplateParameterList)
+ ? LSI
+ : nullptr;
}
return nullptr;
}
-
void Sema::ActOnComment(SourceRange Comment) {
if (!LangOpts.RetainCommentsFromSystemHeaders &&
SourceMgr.isInSystemHeader(Comment.getBegin()))
@@ -2444,8 +2457,8 @@ void Sema::ActOnComment(SourceRange Comment) {
llvm_unreachable("if this is an almost Doxygen comment, "
"it should be ordinary");
}
- Diag(Comment.getBegin(), diag::warn_not_a_doxygen_trailing_member_comment) <<
- FixItHint::CreateReplacement(MagicMarkerRange, MagicMarkerText);
+ Diag(Comment.getBegin(), diag::warn_not_a_doxygen_trailing_member_comment)
+ << FixItHint::CreateReplacement(MagicMarkerRange, MagicMarkerText);
}
Context.addComment(RC);
}
@@ -2454,18 +2467,18 @@ void Sema::ActOnComment(SourceRange Comment) {
ExternalSemaSource::~ExternalSemaSource() {}
char ExternalSemaSource::ID;
-void ExternalSemaSource::ReadMethodPool(Selector Sel) { }
-void ExternalSemaSource::updateOutOfDateSelector(Selector Sel) { }
+void ExternalSemaSource::ReadMethodPool(Selector Sel) {}
+void ExternalSemaSource::updateOutOfDateSelector(Selector Sel) {}
void ExternalSemaSource::ReadKnownNamespaces(
- SmallVectorImpl<NamespaceDecl *> &Namespaces) {
-}
+ SmallVectorImpl<NamespaceDecl *> &Namespaces) {}
void ExternalSemaSource::ReadUndefinedButUsed(
llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) {}
-void ExternalSemaSource::ReadMismatchingDeleteExpressions(llvm::MapVector<
- FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &) {}
+void ExternalSemaSource::ReadMismatchingDeleteExpressions(
+ llvm::MapVector<FieldDecl *,
+ llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &) {}
/// Figure out if an expression could be turned into a call.
///
@@ -2486,7 +2499,7 @@ bool Sema::tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy,
const OverloadExpr *Overloads = nullptr;
bool IsMemExpr = false;
if (E.getType() == Context.OverloadTy) {
- OverloadExpr::FindResult FR = OverloadExpr::find(const_cast<Expr*>(&E));
+ OverloadExpr::FindResult FR = OverloadExpr::find(const_cast<Expr *>(&E));
// Ignore overloads that are pointer-to-member constants.
if (FR.HasFormOfMemberPointer)
@@ -2503,15 +2516,16 @@ bool Sema::tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy,
if (Overloads) {
for (OverloadExpr::decls_iterator it = Overloads->decls_begin(),
- DeclsEnd = Overloads->decls_end(); it != DeclsEnd; ++it) {
+ DeclsEnd = Overloads->decls_end();
+ it != DeclsEnd; ++it) {
OverloadSet.addDecl(*it);
// Check whether the function is a non-template, non-member which takes no
// arguments.
if (IsMemExpr)
continue;
- if (const FunctionDecl *OverloadDecl
- = dyn_cast<FunctionDecl>((*it)->getUnderlyingDecl())) {
+ if (const FunctionDecl *OverloadDecl =
+ dyn_cast<FunctionDecl>((*it)->getUnderlyingDecl())) {
if (OverloadDecl->getMinRequiredArguments() == 0) {
if (!ZeroArgCallReturnTy.isNull() && !Ambiguous &&
(!IsMV || !(OverloadDecl->isCPUDispatchMultiVersion() ||
@@ -2589,7 +2603,8 @@ static void noteOverloads(Sema &S, const UnresolvedSetImpl &Overloads,
unsigned ShownOverloads = 0;
unsigned SuppressedOverloads = 0;
for (UnresolvedSetImpl::iterator It = Overloads.begin(),
- DeclsEnd = Overloads.end(); It != DeclsEnd; ++It) {
+ DeclsEnd = Overloads.end();
+ It != DeclsEnd; ++It) {
if (ShownOverloads >= S.Diags.getNumOverloadCandidatesToShow()) {
++SuppressedOverloads;
continue;
@@ -2613,7 +2628,7 @@ static void noteOverloads(Sema &S, const UnresolvedSetImpl &Overloads,
if (SuppressedOverloads)
S.Diag(FinalNoteLoc, diag::note_ovl_too_many_candidates)
- << SuppressedOverloads;
+ << SuppressedOverloads;
}
static void notePlausibleOverloads(Sema &S, SourceLocation Loc,
@@ -2624,7 +2639,8 @@ static void notePlausibleOverloads(Sema &S, SourceLocation Loc,
UnresolvedSet<2> PlausibleOverloads;
for (OverloadExpr::decls_iterator It = Overloads.begin(),
- DeclsEnd = Overloads.end(); It != DeclsEnd; ++It) {
+ DeclsEnd = Overloads.end();
+ It != DeclsEnd; ++It) {
const auto *OverloadDecl = cast<FunctionDecl>(*It);
QualType OverloadResultTy = OverloadDecl->getReturnType();
if (IsPlausibleResult(OverloadResultTy))
@@ -2639,10 +2655,8 @@ static void notePlausibleOverloads(Sema &S, SourceLocation Loc,
/// outside the call.
static bool IsCallableWithAppend(const Expr *E) {
E = E->IgnoreImplicit();
- return (!isa<CStyleCastExpr>(E) &&
- !isa<UnaryOperator>(E) &&
- !isa<BinaryOperator>(E) &&
- !isa<CXXOperatorCallExpr>(E));
+ return (!isa<CStyleCastExpr>(E) && !isa<UnaryOperator>(E) &&
+ !isa<BinaryOperator>(E) && !isa<CXXOperatorCallExpr>(E));
}
static bool IsCPUDispatchCPUSpecificMultiVersion(const Expr *E) {
@@ -2695,7 +2709,8 @@ bool Sema::tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD,
return true;
}
}
- if (!ForceComplain) return false;
+ if (!ForceComplain)
+ return false;
bool IsMV = IsCPUDispatchCPUSpecificMultiVersion(E.get());
Diag(Loc, PD) << /*not zero-arg*/ 0 << IsMV << Range;
More information about the cfe-commits
mailing list