Skip to content

Commit

Permalink
Merged master:ba10bedf563 into amd-gfx:ec24565c877
Browse files Browse the repository at this point in the history
Local branch amd-gfx ec24565 Merged master:a92ce3b706d into amd-gfx:67cb9805444
Remote branch master ba10bed Revert "[InstrProfiling] Use !associated metadata for counters, data and values"
  • Loading branch information
Sw authored and Sw committed Jun 8, 2020
2 parents ec24565 + ba10bed commit c20d9f1
Show file tree
Hide file tree
Showing 32 changed files with 348 additions and 92 deletions.
5 changes: 5 additions & 0 deletions clang/include/clang/Basic/Diagnostic.h
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,11 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
/// RAII class that determines when any errors have occurred
/// between the time the instance was created and the time it was
/// queried.
///
/// Note that you almost certainly do not want to use this. It's usually
/// meaningless to ask whether a particular scope triggered an error message,
/// because error messages outside that scope can mark things invalid (or cause
/// us to reach an error limit), which can suppress errors within that scope.
class DiagnosticErrorTrap {
DiagnosticsEngine &Diag;
unsigned NumErrors;
Expand Down
6 changes: 4 additions & 2 deletions clang/include/clang/Sema/Scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,10 @@ class Scope {
DeclContext *getEntity() const { return Entity; }
void setEntity(DeclContext *E) { Entity = E; }

bool hasErrorOccurred() const { return ErrorTrap.hasErrorOccurred(); }

/// Determine whether any unrecoverable errors have occurred within this
/// scope. Note that this may return false even if the scope contains invalid
/// declarations or statements, if the errors for those invalid constructs
/// were suppressed because some prior invalid construct was referenced.
bool hasUnrecoverableErrorOccurred() const {
return ErrorTrap.hasUnrecoverableErrorOccurred();
}
Expand Down
13 changes: 13 additions & 0 deletions clang/include/clang/Sema/ScopeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,11 @@ class FunctionScopeInfo {
/// First SEH '__try' statement in the current function.
SourceLocation FirstSEHTryLoc;

private:
/// Used to determine if errors occurred in this function or block.
DiagnosticErrorTrap ErrorTrap;

public:
/// A SwitchStmt, along with a flag indicating if its list of case statements
/// is incomplete (because we dropped an invalid one while parsing).
using SwitchInfo = llvm::PointerIntPair<SwitchStmt*, 1, bool>;
Expand Down Expand Up @@ -375,6 +377,17 @@ class FunctionScopeInfo {

virtual ~FunctionScopeInfo();

/// Determine whether an unrecoverable error has occurred within this
/// function. Note that this may return false even if the function body is
/// invalid, because the errors may be suppressed if they're caused by prior
/// invalid declarations.
///
/// FIXME: Migrate the caller of this to use containsErrors() instead once
/// it's ready.
bool hasUnrecoverableErrorOccurred() const {
return ErrorTrap.hasUnrecoverableErrorOccurred();
}

/// Record that a weak object was accessed.
///
/// Part of the implementation of -Wrepeated-use-of-weak.
Expand Down
6 changes: 6 additions & 0 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -8293,6 +8293,12 @@ class Sema final {
/// We are rewriting a comparison operator in terms of an operator<=>.
RewritingOperatorAsSpaceship,

/// We are initializing a structured binding.
InitializingStructuredBinding,

/// We are marking a class as __dllexport.
MarkingClassDllexported,

/// Added for Template instantiation observation.
/// Memoization means we are _not_ instantiating a template because
/// it is already instantiated (but we entered a context where we
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/Driver/ToolChains/ROCm.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@
#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ROCM_H

#include "clang/Basic/Cuda.h"
#include "clang/Basic/LLVM.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Option/ArgList.h"

namespace clang {
namespace driver {
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Frontend/FrontendActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ class DefaultTemplateInstCallback : public TemplateInstantiationCallback {
return "RequirementInstantiation";
case CodeSynthesisContext::NestedRequirementConstraintsCheck:
return "NestedRequirementConstraintsCheck";
case CodeSynthesisContext::InitializingStructuredBinding:
return "InitializingStructuredBinding";
case CodeSynthesisContext::MarkingClassDllexported:
return "MarkingClassDllexported";
}
return "";
}
Expand Down
3 changes: 0 additions & 3 deletions clang/lib/Parse/ParseExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3369,16 +3369,13 @@ ExprResult Parser::ParseRequiresExpression() {
ParsedAttributes FirstArgAttrs(getAttrFactory());
SourceLocation EllipsisLoc;
llvm::SmallVector<DeclaratorChunk::ParamInfo, 2> LocalParameters;
DiagnosticErrorTrap Trap(Diags);
ParseParameterDeclarationClause(DeclaratorContext::RequiresExprContext,
FirstArgAttrs, LocalParameters,
EllipsisLoc);
if (EllipsisLoc.isValid())
Diag(EllipsisLoc, diag::err_requires_expr_parameter_list_ellipsis);
for (auto &ParamInfo : LocalParameters)
LocalParameterDecls.push_back(cast<ParmVarDecl>(ParamInfo.Param));
if (Trap.hasErrorOccurred())
SkipUntil(tok::r_paren, StopBeforeMatch);
}
Parens.consumeClose();
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/Sema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,7 @@ void Sema::PopCompoundScope() {
/// Determine whether any errors occurred within this function/method/
/// block.
bool Sema::hasAnyUnrecoverableErrorsInThisFunction() const {
return getCurFunction()->ErrorTrap.hasUnrecoverableErrorOccurred();
return getCurFunction()->hasUnrecoverableErrorOccurred();
}

void Sema::setFunctionHasBranchIntoScope() {
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12317,7 +12317,7 @@ void Sema::ActOnInitializerError(Decl *D) {
BD->setInvalidDecl();

// Auto types are meaningless if we can't make sense of the initializer.
if (ParsingInitForAutoVars.count(D)) {
if (VD->getType()->isUndeducedType()) {
D->setInvalidDecl();
return;
}
Expand Down Expand Up @@ -14385,7 +14385,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
// If any errors have occurred, clear out any temporaries that may have
// been leftover. This ensures that these temporaries won't be picked up for
// deletion in some later function.
if (getDiagnostics().hasErrorOccurred() ||
if (getDiagnostics().hasUncompilableErrorOccurred() ||
getDiagnostics().getSuppressAllDiagnostics()) {
DiscardCleanupsInEvaluationContext();
}
Expand Down Expand Up @@ -14441,7 +14441,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
// If any errors have occurred, clear out any temporaries that may have
// been leftover. This ensures that these temporaries won't be picked up for
// deletion in some later function.
if (getDiagnostics().hasErrorOccurred()) {
if (getDiagnostics().hasUncompilableErrorOccurred()) {
DiscardCleanupsInEvaluationContext();
}

Expand Down
44 changes: 28 additions & 16 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1101,16 +1101,17 @@ static QualType getTupleLikeElementType(Sema &S, SourceLocation Loc,
}

namespace {
struct BindingDiagnosticTrap {
struct InitializingBinding {
Sema &S;
DiagnosticErrorTrap Trap;
BindingDecl *BD;

BindingDiagnosticTrap(Sema &S, BindingDecl *BD)
: S(S), Trap(S.Diags), BD(BD) {}
~BindingDiagnosticTrap() {
if (Trap.hasErrorOccurred())
S.Diag(BD->getLocation(), diag::note_in_binding_decl_init) << BD;
InitializingBinding(Sema &S, BindingDecl *BD) : S(S) {
Sema::CodeSynthesisContext Ctx;
Ctx.Kind = Sema::CodeSynthesisContext::InitializingStructuredBinding;
Ctx.PointOfInstantiation = BD->getLocation();
Ctx.Entity = BD;
S.pushCodeSynthesisContext(Ctx);
}
~InitializingBinding() {
S.popCodeSynthesisContext();
}
};
}
Expand Down Expand Up @@ -1159,7 +1160,7 @@ static bool checkTupleLikeDecomposition(Sema &S,

unsigned I = 0;
for (auto *B : Bindings) {
BindingDiagnosticTrap Trap(S, B);
InitializingBinding InitContext(S, B);
SourceLocation Loc = B->getLocation();

ExprResult E = S.BuildDeclRefExpr(Src, DecompType, VK_LValue, Loc);
Expand Down Expand Up @@ -5797,6 +5798,23 @@ static void ReferenceDllExportedMembers(Sema &S, CXXRecordDecl *Class) {
// declaration.
return;

// Add a context note to explain how we got to any diagnostics produced below.
struct MarkingClassDllexported {
Sema &S;
MarkingClassDllexported(Sema &S, CXXRecordDecl *Class,
SourceLocation AttrLoc)
: S(S) {
Sema::CodeSynthesisContext Ctx;
Ctx.Kind = Sema::CodeSynthesisContext::MarkingClassDllexported;
Ctx.PointOfInstantiation = AttrLoc;
Ctx.Entity = Class;
S.pushCodeSynthesisContext(Ctx);
}
~MarkingClassDllexported() {
S.popCodeSynthesisContext();
}
} MarkingDllexportedContext(S, Class, ClassAttr->getLocation());

if (S.Context.getTargetInfo().getTriple().isWindowsGNUEnvironment())
S.MarkVTableUsed(Class->getLocation(), Class, true);

Expand Down Expand Up @@ -5832,13 +5850,7 @@ static void ReferenceDllExportedMembers(Sema &S, CXXRecordDecl *Class) {
// defaulted methods, and the copy and move assignment operators. The
// latter are exported even if they are trivial, because the address of
// an operator can be taken and should compare equal across libraries.
DiagnosticErrorTrap Trap(S.Diags);
S.MarkFunctionReferenced(Class->getLocation(), MD);
if (Trap.hasErrorOccurred()) {
S.Diag(ClassAttr->getLocation(), diag::note_due_to_dllexported_class)
<< Class << !S.getLangOpts().CPlusPlus11;
break;
}

// There is no later point when we will see the definition of this
// function, so pass it to the consumer now.
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7595,13 +7595,13 @@ ExprResult Sema::BuildCXXMemberCallExpr(Expr *E, NamedDecl *FoundDecl,
// a difference in ARC, but outside of ARC the resulting block literal
// follows the normal lifetime rules for block literals instead of being
// autoreleased.
DiagnosticErrorTrap Trap(Diags);
PushExpressionEvaluationContext(
ExpressionEvaluationContext::PotentiallyEvaluated);
ExprResult BlockExp = BuildBlockForLambdaConversion(
Exp.get()->getExprLoc(), Exp.get()->getExprLoc(), Method, Exp.get());
PopExpressionEvaluationContext();

// FIXME: This note should be produced by a CodeSynthesisContext.
if (BlockExp.isInvalid())
Diag(Exp.get()->getExprLoc(), diag::note_lambda_to_block_conv);
return BlockExp;
Expand Down
46 changes: 16 additions & 30 deletions clang/lib/Sema/SemaStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2127,18 +2127,22 @@ StmtResult Sema::ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc,
return StmtError();
}

// This function is responsible for attaching an initializer to LoopVar. We
// must call ActOnInitializerError if we fail to do so.
Decl *LoopVar = DS->getSingleDecl();
if (LoopVar->isInvalidDecl() || !Range ||
DiagnoseUnexpandedParameterPack(Range, UPPC_Expression)) {
LoopVar->setInvalidDecl();
ActOnInitializerError(LoopVar);
return StmtError();
}

// Build the coroutine state immediately and not later during template
// instantiation
if (!CoawaitLoc.isInvalid()) {
if (!ActOnCoroutineBodyStart(S, CoawaitLoc, "co_await"))
if (!ActOnCoroutineBodyStart(S, CoawaitLoc, "co_await")) {
ActOnInitializerError(LoopVar);
return StmtError();
}
}

// Build auto && __range = range-init
Expand All @@ -2150,7 +2154,7 @@ StmtResult Sema::ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc,
std::string("__range") + DepthStr);
if (FinishForRangeVarDecl(*this, RangeVar, Range, RangeLoc,
diag::err_for_range_deduction_failure)) {
LoopVar->setInvalidDecl();
ActOnInitializerError(LoopVar);
return StmtError();
}

Expand All @@ -2159,14 +2163,20 @@ StmtResult Sema::ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc,
BuildDeclaratorGroup(MutableArrayRef<Decl *>((Decl **)&RangeVar, 1));
StmtResult RangeDecl = ActOnDeclStmt(RangeGroup, RangeLoc, RangeLoc);
if (RangeDecl.isInvalid()) {
LoopVar->setInvalidDecl();
ActOnInitializerError(LoopVar);
return StmtError();
}

return BuildCXXForRangeStmt(
StmtResult R = BuildCXXForRangeStmt(
ForLoc, CoawaitLoc, InitStmt, ColonLoc, RangeDecl.get(),
/*BeginStmt=*/nullptr, /*EndStmt=*/nullptr,
/*Cond=*/nullptr, /*Inc=*/nullptr, DS, RParenLoc, Kind);
if (R.isInvalid()) {
ActOnInitializerError(LoopVar);
return StmtError();
}

return R;
}

/// Create the initialization, compare, and increment steps for
Expand Down Expand Up @@ -2349,22 +2359,6 @@ static StmtResult RebuildForRangeWithDereference(Sema &SemaRef, Scope *S,
AdjustedRange.get(), RParenLoc, Sema::BFRK_Rebuild);
}

namespace {
/// RAII object to automatically invalidate a declaration if an error occurs.
struct InvalidateOnErrorScope {
InvalidateOnErrorScope(Sema &SemaRef, Decl *D, bool Enabled)
: Trap(SemaRef.Diags), D(D), Enabled(Enabled) {}
~InvalidateOnErrorScope() {
if (Enabled && Trap.hasErrorOccurred())
D->setInvalidDecl();
}

DiagnosticErrorTrap Trap;
Decl *D;
bool Enabled;
};
}

/// BuildCXXForRangeStmt - Build or instantiate a C++11 for-range statement.
StmtResult Sema::BuildCXXForRangeStmt(SourceLocation ForLoc,
SourceLocation CoawaitLoc, Stmt *InitStmt,
Expand All @@ -2391,11 +2385,6 @@ StmtResult Sema::BuildCXXForRangeStmt(SourceLocation ForLoc,
DeclStmt *LoopVarDS = cast<DeclStmt>(LoopVarDecl);
VarDecl *LoopVar = cast<VarDecl>(LoopVarDS->getSingleDecl());

// If we hit any errors, mark the loop variable as invalid if its type
// contains 'auto'.
InvalidateOnErrorScope Invalidate(*this, LoopVar,
LoopVar->getType()->isUndeducedType());

StmtResult BeginDeclStmt = Begin;
StmtResult EndDeclStmt = End;
ExprResult NotEqExpr = Cond, IncrExpr = Inc;
Expand Down Expand Up @@ -2434,11 +2423,8 @@ StmtResult Sema::BuildCXXForRangeStmt(SourceLocation ForLoc,
QualType RangeType = Range->getType();

if (RequireCompleteType(RangeLoc, RangeType,
diag::err_for_range_incomplete_type)) {
if (LoopVar->getType()->isUndeducedType())
LoopVar->setInvalidDecl();
diag::err_for_range_incomplete_type))
return StmtError();
}

// Build auto __begin = begin-expr, __end = end-expr.
// Divide by 2, since the variables are in the inner scope (loop body).
Expand Down
16 changes: 16 additions & 0 deletions clang/lib/Sema/SemaTemplateInstantiate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ bool Sema::CodeSynthesisContext::isInstantiationRecord() const {
case ParameterMappingSubstitution:
case ConstraintNormalization:
case RewritingOperatorAsSpaceship:
case InitializingStructuredBinding:
case MarkingClassDllexported:
return false;

// This function should never be called when Kind's value is Memoization.
Expand Down Expand Up @@ -760,6 +762,18 @@ void Sema::PrintInstantiationStack() {
diag::note_rewriting_operator_as_spaceship);
break;

case CodeSynthesisContext::InitializingStructuredBinding:
Diags.Report(Active->PointOfInstantiation,
diag::note_in_binding_decl_init)
<< cast<BindingDecl>(Active->Entity);
break;

case CodeSynthesisContext::MarkingClassDllexported:
Diags.Report(Active->PointOfInstantiation,
diag::note_due_to_dllexported_class)
<< cast<CXXRecordDecl>(Active->Entity) << !getLangOpts().CPlusPlus11;
break;

case CodeSynthesisContext::Memoization:
break;

Expand Down Expand Up @@ -861,6 +875,8 @@ Optional<TemplateDeductionInfo *> Sema::isSFINAEContext() const {
case CodeSynthesisContext::DeclaringImplicitEqualityComparison:
case CodeSynthesisContext::DefiningSynthesizedFunction:
case CodeSynthesisContext::RewritingOperatorAsSpaceship:
case CodeSynthesisContext::InitializingStructuredBinding:
case CodeSynthesisContext::MarkingClassDllexported:
// This happens in a context unrelated to template instantiation, so
// there is no SFINAE.
return None;
Expand Down
9 changes: 5 additions & 4 deletions clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5879,10 +5879,11 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
if (!Result) {
if (isa<UsingShadowDecl>(D)) {
// UsingShadowDecls can instantiate to nothing because of using hiding.
} else if (Diags.hasErrorOccurred()) {
// We've already complained about something, so most likely this
// declaration failed to instantiate. There's no point in complaining
// further, since this is normal in invalid code.
} else if (Diags.hasUncompilableErrorOccurred()) {
// We've already complained about some ill-formed code, so most likely
// this declaration failed to instantiate. There's no point in
// complaining further, since this is normal in invalid code.
// FIXME: Use more fine-grained 'invalid' tracking for this.
} else if (IsBeingInstantiated) {
// The class in which this member exists is currently being
// instantiated, and we haven't gotten around to instantiating this
Expand Down
Loading

0 comments on commit c20d9f1

Please sign in to comment.